Files
fitness/app/Models/Workout.php
T
rootandClaude Sonnet 5 ebd0578dc9 Add multi-week workout programs
A Workout was a single flat session with no way to schedule several
across weeks/days as a structured plan (e.g. Push/Pull/Legs over 4
weeks) - every user started from a blank builder each time, and there
was no template concept at all.

Adds a Program (title, description, week count) that Workouts can
optionally belong to via nullable program_id/week_number/day_number
columns, reusing all existing workout and session-tracking
infrastructure rather than building a parallel system. The program show
page lays out the schedule week by week and derives progress (completed
vs total) from the user's existing WorkoutSession completions - no new
enrollment/progress-tracking concept needed. Deleting a program
unschedules its workouts (nullOnDelete) rather than destroying them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-10 12:21:47 +03:00

59 lines
1.4 KiB
PHP

<?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',
'program_id',
'week_number',
'day_number',
];
protected $casts = [
'estimated_minutes' => 'integer',
'week_number' => 'integer',
'day_number' => 'integer',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function program(): BelongsTo
{
return $this->belongsTo(Program::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');
}
public function favoritedBy()
{
return $this->belongsToMany(User::class, 'workout_favorites')->withTimestamps();
}
}