2025-10-02 22:52:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
|
|
|
|
|
class Workout extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'user_id',
|
|
|
|
|
'title',
|
|
|
|
|
'notes',
|
|
|
|
|
'estimated_minutes',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'estimated_minutes' => 'integer',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function user(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function items(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(WorkoutExercise::class)->orderBy('position');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function exercises(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Exercise::class, 'workout_exercises')
|
|
|
|
|
->withPivot(['id', 'position', 'sets', 'reps', 'weight', 'rest_seconds', 'notes'])
|
|
|
|
|
->withTimestamps()
|
|
|
|
|
->orderBy('workout_exercises.position');
|
|
|
|
|
}
|
2025-10-02 23:52:07 +03:00
|
|
|
|
|
|
|
|
public function favoritedBy()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(User::class, 'workout_favorites')->withTimestamps();
|
|
|
|
|
}
|
2025-10-02 22:52:13 +03:00
|
|
|
}
|