Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a route group with the prefix 'admin'.
Laravel
Route::[1](['prefix' => 'admin'], function () { Route::get('/', function () { return 'Admin area'; }); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Route::prefix() directly without group.
Using Route::middleware() instead of group.
Using Route::resource() which is for resource controllers.
✗ Incorrect
In Laravel, to define a group of routes with a prefix, you use Route::group().
2fill in blank
mediumComplete the code to set the prefix 'dashboard' for the route group.
Laravel
Route::group(['[1]' => 'dashboard'], function () { Route::get('/', function () { return 'Dashboard home'; }); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'middleware' instead of 'prefix'.
Using 'namespace' which is for controller namespaces.
Using 'name' which is for route naming prefixes.
✗ Incorrect
The 'prefix' key in the group options sets the URL prefix for all routes inside the group.
3fill in blank
hardFix the error in the route group to correctly apply the prefix 'api'.
Laravel
Route::group([1], function () { Route::get('/users', function () { return 'API users'; }); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an array.
Using prefix('api') which is not valid here.
Using array() syntax inconsistently.
✗ Incorrect
Route::group() expects an array of options as the first argument, so it must be ['prefix' => 'api'].
4fill in blank
hardFill both blanks to create a route group with prefix 'admin' and middleware 'auth'.
Laravel
Route::group(['[1]' => 'admin', '[2]' => 'auth'], function () { Route::get('/dashboard', function () { return 'Admin dashboard'; }); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'namespace' with 'middleware'.
Using 'name' instead of 'prefix'.
Forgetting to use an array for options.
✗ Incorrect
The 'prefix' key sets the URL prefix, and 'middleware' applies middleware to the group.
5fill in blank
hardFill all three blanks to create a route group with prefix 'api', middleware 'auth:sanctum', and namespace 'Api'.
Laravel
Route::group(['[1]' => 'api', '[2]' => 'auth:sanctum', '[3]' => 'Api'], function () { Route::get('/profile', function () { return 'User profile'; }); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' instead of 'namespace'.
Mixing up the order of keys.
Forgetting to use an array for options.
✗ Incorrect
The keys 'prefix', 'middleware', and 'namespace' set the URL prefix, middleware, and controller namespace respectively.