group(function () { Route::get('/consoles', function () { return response()->json(Console::withCount('games')->orderBy('name')->get()); }); Route::get('/games', function () { $query = Game::with('console'); if (request()->has('console')) { $query->whereHas('console', function ($q) { $q->where('slug', request()->console); }); } if (request()->has('search')) { $query->where('title', 'like', '%'.request()->search.'%'); } return response()->json($query->orderBy('title')->paginate(24)); }); Route::get('/games/{game}', function (Game $game) { $game->load(['console', 'romFiles']); return response()->json($game); }); });