Replace capped exercise picker with a real search combobox

The workout builder's "add exercise" dropdown was Exercise::orderBy
('name')->limit(50) with no search. Harmless with a handful of seeded
exercises, but once the library is populated with real data (1000+),
users could only ever add exercises starting around A-D - the core
"build a workout" flow would be effectively broken.

Replaces it with a debounced Alpine.js combobox backed by a new
GET /workouts/{workout}/exercises/search endpoint (owner-only, JSON,
capped at 20 results, respects each user's custom exercise aliases).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-10 12:02:08 +03:00
co-authored by Claude Sonnet 5
parent 0c6a297198
commit 0a44b97232
4 changed files with 104 additions and 9 deletions
+17 -1
View File
@@ -42,10 +42,26 @@ class WorkoutController extends Controller
{
$this->authorizeWorkout($workout);
$workout->load(['items.exercise']);
$exercises = Exercise::orderBy('name')->limit(50)->get(['id','name','slug']);
$exercises = Exercise::orderBy('name')->limit(20)->get(['id','name','slug']);
return view('workouts.show', compact('workout', 'exercises'));
}
public function searchExercises(Request $request, Workout $workout)
{
$this->authorizeWorkout($workout);
$q = trim((string) $request->query('q', ''));
$exercises = Exercise::query()
->with(['aliases' => fn ($rel) => $rel->where('user_id', Auth::id())])
->when($q !== '', fn ($qb) => $qb->where('name', 'like', "%{$q}%"))
->orderBy('name')
->limit(20)
->get(['id', 'name'])
->map(fn ($e) => ['id' => $e->id, 'name' => $e->display_name]);
return response()->json($exercises);
}
// Legacy builder route -> redirect to create
public function builder()
{