Challenge 2: Group Routes Under a Prefix — Possible Solution ==================================================================== // routes/web.php use Illuminate\Support\Facades\Route; Route::prefix('api')->group(function () { Route::get('/books', function () { return 'All books'; })->name('api.books.index'); Route::get('/books/{id}', function (string $id) { return "Showing book #{$id}"; })->where('id', '[0-9]+')->name('api.books.show'); Route::get('/books/category/{slug}', function (string $slug) { return "Books in category: {$slug}"; })->name('api.books.category'); }); FINAL FULL PATHS FOR EACH ROUTE ------------------------------------ Given the routes are grouped under the "api" prefix: - /books -> combined with the "api" prefix -> /api/books - /books/{id} -> full path: /api/books/{id} (e.g. /api/books/42) - /books/category/{slug} -> full path: /api/books/category/{slug} (e.g. /api/books/category/sci-fi) WHY THIS WORKS -------------- - Route::prefix('api')->group(function () { ... }) wraps every route DEFINED INSIDE the closure with the "api/" prefix automatically — each individual Route::get(...) call inside the group is written as if it owned the root, exactly the way Django's include()'d app urls.py never mentions its own prefix either. - Route names were also updated to include an "api." prefix (api.books.index instead of just books.index) — this isn't required by Route::prefix() itself, but it's a common convention to avoid a name collision if the same route names ever get reused elsewhere (e.g. a non-API "books.index" route serving HTML pages at the plain /books path, alongside this JSON-oriented api.books.index). - Because the prefix is applied entirely by the group wrapper, moving these three routes to a different prefix later (say, "v1/api") means changing the one Route::prefix(...) call, not each route definition individually.