Challenge - 5 Problems
Laravel Route Groups Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the URL prefix for routes inside this group?
Consider this Laravel route group:
What URL path will you visit to see the 'Admin Dashboard'?
Route::prefix('admin')->group(function () {
Route::get('/dashboard', function () {
return 'Admin Dashboard';
});
});What URL path will you visit to see the 'Admin Dashboard'?
Laravel
Route::prefix('admin')->group(function () { Route::get('/dashboard', function () { return 'Admin Dashboard'; }); });
Attempts:
2 left
💡 Hint
Think about how the prefix adds to the route path.
✗ Incorrect
The prefix 'admin' is added before all routes inside the group, so the full URL becomes '/admin/dashboard'.
📝 Syntax
intermediate2:00remaining
Which option correctly applies middleware to a route group?
You want to apply the 'auth' middleware to all routes inside a group. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Check the correct syntax for passing middleware in a group.
✗ Incorrect
The correct syntax for applying middleware in a group can use either an array as the first argument to Route::group(), or the middleware() method before group().
❓ state_output
advanced2:00remaining
What is the output of this nested route group?
Given this Laravel route group code:
What URL path will return 'Users v1'?
Route::prefix('api')->group(function () {
Route::prefix('v1')->group(function () {
Route::get('/users', function () {
return 'Users v1';
});
});
});What URL path will return 'Users v1'?
Laravel
Route::prefix('api')->group(function () { Route::prefix('v1')->group(function () { Route::get('/users', function () { return 'Users v1'; }); }); });
Attempts:
2 left
💡 Hint
Prefixes stack in the order they are nested.
✗ Incorrect
The outer prefix 'api' and inner prefix 'v1' combine to form '/api/v1/users'.
🔧 Debug
advanced2:00remaining
Why does this route group cause a syntax error?
Look at this code:
Why does this code cause a syntax error?
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function () {
Route::get('/dashboard', function () {
return 'Dashboard';
});
});Why does this code cause a syntax error?
Laravel
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function () { Route::get('/dashboard', function () { return 'Dashboard'; }); });
Attempts:
2 left
💡 Hint
Check the array syntax and function declaration carefully.
✗ Incorrect
The array syntax and function declaration are correct; this code does not cause a syntax error.
🧠 Conceptual
expert3:00remaining
How does the 'as' option affect route names in groups?
Consider this route group:
What is the full route name for the '/users' route?
Route::name('admin.')->group(function () {
Route::get('/users', function () {
return 'Users';
})->name('users');
});What is the full route name for the '/users' route?
Laravel
Route::name('admin.')->group(function () { Route::get('/users', function () { return 'Users'; })->name('users'); });
Attempts:
2 left
💡 Hint
The 'name' prefix adds before the route's own name.
✗ Incorrect
The 'name' method on the group adds 'admin.' before each route's name, so the full name is 'admin.users'.