favorites
This commit is contained in:
@@ -39,4 +39,9 @@ class Exercise extends Model
|
||||
{
|
||||
return $this->hasMany(WorkoutExercise::class);
|
||||
}
|
||||
|
||||
public function favoritedBy()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'exercise_favorites')->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,4 +51,25 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->hasMany(Workout::class);
|
||||
}
|
||||
|
||||
public function favoriteExercises()
|
||||
{
|
||||
return $this->belongsToMany(Exercise::class, 'exercise_favorites')->withTimestamps();
|
||||
}
|
||||
|
||||
public function favoriteWorkouts()
|
||||
{
|
||||
return $this->belongsToMany(Workout::class, 'workout_favorites')->withTimestamps();
|
||||
}
|
||||
|
||||
// Helpers
|
||||
public function hasFavoritedExercise(Exercise $exercise): bool
|
||||
{
|
||||
return $this->favoriteExercises()->where('exercise_id', $exercise->id)->exists();
|
||||
}
|
||||
|
||||
public function hasFavoritedWorkout(Workout $workout): bool
|
||||
{
|
||||
return $this->favoriteWorkouts()->where('workout_id', $workout->id)->exists();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,4 +40,9 @@ class Workout extends Model
|
||||
->withTimestamps()
|
||||
->orderBy('workout_exercises.position');
|
||||
}
|
||||
|
||||
public function favoritedBy()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'workout_favorites')->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user