Challenge - 5 Problems
Laravel Route Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the URL generated by this named route?
Given the following Laravel route definition, what URL will be generated by calling
route('profile.show', ['id' => 5])?Laravel
Route::get('/user/{id}', function ($id) { return "User $id profile"; })->name('profile.show');
Attempts:
2 left
💡 Hint
Look at the route URL pattern and how parameters are passed in named routes.
✗ Incorrect
The route is defined with URL pattern /user/{id}. Using route('profile.show', ['id' => 5]) replaces {id} with 5, so the generated URL is /user/5.
📝 Syntax
intermediate2:00remaining
Which option correctly names a route in Laravel?
Select the correct syntax to assign the name 'dashboard.home' to a route that responds to GET requests at '/dashboard'.
Attempts:
2 left
💡 Hint
Check the Laravel documentation for the method used to name routes.
✗ Incorrect
The correct method to name a route is ->name('route.name') chained after the route definition. Option B uses this correctly.
❓ state_output
advanced2:00remaining
What is the output of this route helper call?
Consider this route group with a name prefix. What is the output of
route('admin.users.index')?Laravel
Route::name('admin.')->group(function () { Route::get('/users', function () { return 'Users list'; })->name('users.index'); });
Attempts:
2 left
💡 Hint
Name prefixes affect route names, not URLs.
✗ Incorrect
The name prefix admin. adds to the route's name, making it admin.users.index. The URL remains /users because no URL prefix is set.
🔧 Debug
advanced2:00remaining
Why does this named route call cause an error?
Given this route definition, why does calling
route('product.show') cause an error?Laravel
Route::get('/product/{id}', function ($id) { return "Product $id"; })->name('product.show');
Attempts:
2 left
💡 Hint
Check if all required parameters are passed when generating URLs.
✗ Incorrect
The route URL requires an 'id' parameter. Calling route('product.show') without passing 'id' causes an error because Laravel cannot generate the URL.
🧠 Conceptual
expert3:00remaining
How does Laravel resolve route names with nested groups?
Given nested route groups with name prefixes, what is the full route name for the inner route?
Laravel
Route::name('api.')->group(function () { Route::name('v1.')->group(function () { Route::get('/items', function () { return 'Items list'; })->name('items.index'); }); });
Attempts:
2 left
💡 Hint
Name prefixes concatenate in the order of nesting.
✗ Incorrect
Laravel concatenates name prefixes from outer to inner groups. So api. + v1. + items.index becomes api.v1.items.index.