Add per-exercise personal record tracking

Session tracking only ever stored a done boolean - no record of what
weight or reps were actually performed, so there was no way to derive
real progress data even though the dashboard implied "progress
tracking" was a thing. Workout templates only hold a static planned
value, not a history of performance.

Adds actual_weight/actual_reps to workout_session_items, captured
inline when checking off a set in a session (defaults to the workout's
planned weight/reps, editable before confirming). The exercise detail
page now shows the user's personal best (heaviest completed set, tie
broken by reps) computed from their completed session history across
all workouts containing that exercise.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-10 12:15:14 +03:00
co-authored by Claude Sonnet 5
parent 1cc21ad0c5
commit fa8bf46f8a
11 changed files with 248 additions and 2 deletions
@@ -6,6 +6,7 @@ use App\Models\BodyPart;
use App\Models\Equipment;
use App\Models\Exercise;
use App\Models\Muscle;
use App\Models\WorkoutSessionItem;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@@ -104,9 +105,23 @@ class ExerciseController extends Controller
$similarExercises = $similarQuery->get();
$personalBest = null;
if (Auth::check()) {
$personalBest = WorkoutSessionItem::query()
->with('session')
->whereHas('workoutExercise', fn ($q) => $q->where('exercise_id', $exercise->id))
->whereHas('session', fn ($q) => $q->where('user_id', Auth::id()))
->where('done', true)
->whereNotNull('actual_weight')
->orderByDesc('actual_weight')
->orderByDesc('actual_reps')
->first();
}
return view('exercises.show', [
'exercise' => $exercise,
'similarExercises' => $similarExercises,
'personalBest' => $personalBest,
]);
}
}
@@ -58,6 +58,11 @@ class WorkoutSessionController extends Controller
abort(404);
}
$data = $request->validate([
'actual_weight' => ['nullable', 'numeric', 'min:0', 'max:9999.99'],
'actual_reps' => ['nullable', 'integer', 'min:0', 'max:1000'],
]);
$si = WorkoutSessionItem::firstOrCreate([
'session_id' => $session->id,
'workout_exercise_id' => $item->id,
@@ -66,6 +71,14 @@ class WorkoutSessionController extends Controller
]);
$si->done = !$si->done;
if ($si->done) {
if (array_key_exists('actual_weight', $data) && $data['actual_weight'] !== null) {
$si->actual_weight = $data['actual_weight'];
}
if (array_key_exists('actual_reps', $data) && $data['actual_reps'] !== null) {
$si->actual_reps = $data['actual_reps'];
}
}
$si->save();
return back();