favoriteExercises()->where('exercise_id', $exercise->id)->exists(); if ($exists) { $user->favoriteExercises()->detach($exercise->id); } else { $user->favoriteExercises()->attach($exercise->id); } return response()->json(['favorited' => !$exists]); } public function toggleWorkout(Workout $workout): JsonResponse { $user = Auth::user(); $exists = $user->favoriteWorkouts()->where('workout_id', $workout->id)->exists(); if ($exists) { $user->favoriteWorkouts()->detach($workout->id); } else { $user->favoriteWorkouts()->attach($workout->id); } return response()->json(['favorited' => !$exists]); } public function toggleYogaPose(YogaPose $pose): JsonResponse { $user = Auth::user(); $exists = $user->favoriteYogaPoses()->where('yoga_pose_id', $pose->id)->exists(); if ($exists) { $user->favoriteYogaPoses()->detach($pose->id); } else { $user->favoriteYogaPoses()->attach($pose->id); } return response()->json(['favorited' => !$exists]); } }