0
0
Laravelframework~10 mins

Route prefixes in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Agroup
Bprefix
Cmiddleware
Dresource
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.
2fill in blank
medium

Complete 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'
Amiddleware
Bprefix
Cname
Dnamespace
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.
3fill in blank
hard

Fix 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'
A['prefix' => 'api']
B'prefix' => 'api'
Carray('prefix' => 'api')
Dprefix('api')
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.
4fill in blank
hard

Fill 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'
Aprefix
Bmiddleware
Cnamespace
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'namespace' with 'middleware'.
Using 'name' instead of 'prefix'.
Forgetting to use an array for options.
5fill in blank
hard

Fill 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'
Aprefix
Bmiddleware
Cnamespace
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' instead of 'namespace'.
Mixing up the order of keys.
Forgetting to use an array for options.