is_trainer was captured at signup and stored, but nothing in the app used it - no client roster, no way to assign anything, a dead flag that misled users who checked it during registration. Adds a trainer/client link (a trainer adds a client by the email they registered with) and lets a trainer create workouts directly on a client's account (assigned_by_trainer_id on workouts). Deliberately scoped for privacy: a trainer only ever sees/manages the workouts they authored and assigned - not a client's other private data (their own workouts, weight log, health notes, session/completion history). That boundary needs a consent or notification system to relax safely, which doesn't exist yet, so it's left for a follow-up rather than building it half-safe. WorkoutController's authorization now distinguishes "manage" (owner or assigning trainer - view, add/edit exercises) from "own" (owner only - delete), so a trainer can build out an assigned workout's exercises after creating it, but can't delete a client's workout out from under them. Found a real bug via live testing before committing: the client roster page eager-loaded `assignedWorkouts` (keyed by assigned_by_trainer_id) on each client record, which is the trainer's own perspective, not the client's - so it silently showed "no workouts assigned" even after assigning one. Fixed to eager-load `workouts` filtered by assigned_by_trainer_id instead, with a regression test. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
38 lines
2.6 KiB
PHP
38 lines
2.6 KiB
PHP
<x-app-layout>
|
|
<section class="bg-white dark:bg-gray-900 border-b border-gray-100 dark:border-gray-800">
|
|
<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8 py-8">
|
|
<a href="{{ route('trainer.clients') }}" class="text-sm text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white">← My Clients</a>
|
|
<h1 class="mt-2 text-2xl sm:text-3xl font-extrabold tracking-tight text-gray-900 dark:text-white">Assign a Workout to {{ $client->name }}</h1>
|
|
<p class="mt-2 text-gray-600 dark:text-gray-300">You'll be able to add exercises to it right after creating it.</p>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="mx-auto max-w-2xl px-4 sm:px-6 lg:px-8 py-8">
|
|
@if ($errors->any())
|
|
<div class="mb-4 rounded-xl bg-red-50 text-red-700 px-4 py-3">
|
|
<ul class="list-disc ms-5 text-sm">
|
|
@foreach ($errors->all() as $error)
|
|
<li>{{ $error }}</li>
|
|
@endforeach
|
|
</ul>
|
|
</div>
|
|
@endif
|
|
<form method="POST" action="{{ route('trainer.workouts.store', $client) }}" class="space-y-5 bg-white dark:bg-gray-800 rounded-2xl p-6 ring-1 ring-gray-200 dark:ring-gray-700">
|
|
@csrf
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Title</label>
|
|
<input type="text" name="title" required placeholder="e.g. Week 1 - Push Day" class="mt-1 w-full rounded-xl border-gray-300 dark:border-gray-700 bg-white/80 dark:bg-gray-900 text-gray-900 dark:text-gray-100 px-3 py-2">
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Estimated minutes</label>
|
|
<input type="number" name="estimated_minutes" min="1" max="600" class="mt-1 w-32 rounded-xl border-gray-300 dark:border-gray-700 bg-white/80 dark:bg-gray-900 text-gray-900 dark:text-gray-100 px-3 py-2">
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Notes</label>
|
|
<textarea name="notes" rows="3" class="mt-1 w-full rounded-xl border-gray-300 dark:border-gray-700 bg-white/80 dark:bg-gray-900 text-gray-900 dark:text-gray-100 px-3 py-2"></textarea>
|
|
</div>
|
|
<button type="submit" class="inline-flex items-center rounded-xl bg-gradient-to-r from-fuchsia-600 to-indigo-600 px-4 py-2 text-sm font-semibold text-white shadow hover:from-fuchsia-500 hover:to-indigo-500">Assign Workout</button>
|
|
</form>
|
|
</section>
|
|
</x-app-layout>
|