Add favorite toggle to yoga poses

Exercises and workouts both have a favorite toggle; yoga poses had an
otherwise identical browse/filter UX but no way to favorite them - an
inconsistency rather than a deliberate omission. Mirrors the existing
exercise/workout favorite pattern exactly: a pivot table, a
belongsToMany on User, and a toggle button on the pose detail page.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-10 12:04:50 +03:00
co-authored by Claude Sonnet 5
parent 0a44b97232
commit 7769d2038a
6 changed files with 94 additions and 0 deletions
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Models\Exercise;
use App\Models\Workout;
use App\Models\YogaPose;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
@@ -39,4 +40,18 @@ class FavoriteController extends Controller
}
return back()->with('status', $msg);
}
public function toggleYogaPose(YogaPose $pose): RedirectResponse
{
$user = Auth::user();
$exists = $user->favoriteYogaPoses()->where('yoga_pose_id', $pose->id)->exists();
if ($exists) {
$user->favoriteYogaPoses()->detach($pose->id);
$msg = 'Removed from favorites';
} else {
$user->favoriteYogaPoses()->attach($pose->id);
$msg = 'Added to favorites';
}
return back()->with('status', $msg);
}
}
+10
View File
@@ -79,6 +79,11 @@ class User extends Authenticatable
return $this->belongsToMany(Workout::class, 'workout_favorites')->withTimestamps();
}
public function favoriteYogaPoses()
{
return $this->belongsToMany(YogaPose::class, 'yoga_pose_favorites')->withTimestamps();
}
// Helpers
public function hasFavoritedExercise(Exercise $exercise): bool
{
@@ -89,4 +94,9 @@ class User extends Authenticatable
{
return $this->favoriteWorkouts()->where('workout_id', $workout->id)->exists();
}
public function hasFavoritedYogaPose(YogaPose $pose): bool
{
return $this->favoriteYogaPoses()->where('yoga_pose_id', $pose->id)->exists();
}
}