0
0
Laravelframework~10 mins

Route middleware 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 apply the 'auth' middleware to the route.

Laravel
Route::get('/dashboard', function () {
    return view('dashboard');
})->[1]('auth');
Drag options to blanks, or click blank then click option'
Aname
Bprefix
Cgroup
Dmiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prefix' instead of 'middleware'.
Trying to use 'group' on a single route.
2fill in blank
medium

Complete the code to apply multiple middleware 'auth' and 'verified' to the route.

Laravel
Route::post('/profile', function () {
    // Update profile
})->middleware([[1]]);
Drag options to blanks, or click blank then click option'
A'auth', 'verified'
B'auth|verified'
C'auth', 'guest'
D'verified', 'guest'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single string with pipe '|' instead of an array.
Including middleware that don't apply here.
3fill in blank
hard

Fix the error in the middleware group definition to apply 'auth' and 'admin' middleware.

Laravel
Route::middleware([1])->group(function () {
    Route::get('/admin', function () {
        // Admin dashboard
    });
});
Drag options to blanks, or click blank then click option'
A'auth|admin'
B'auth, admin'
C['auth', 'admin']
Dauth, admin
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string with commas or pipes instead of an array.
Not quoting middleware names.
4fill in blank
hard

Fill both blanks to define a route group with 'auth' middleware and prefix 'admin'.

Laravel
Route::[1](['middleware' => '[2]', 'prefix' => 'admin'], function () {
    Route::get('/dashboard', function () {
        // Admin dashboard
    });
});
Drag options to blanks, or click blank then click option'
Agroup
Bmiddleware
Cauth
Dprefix
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'middleware' method instead of 'group' for grouping.
Using 'prefix' as middleware name.
5fill in blank
hard

Fill all three blanks to create a route with 'auth' middleware, named 'profile.show', and URL '/profile'.

Laravel
Route::get('[1]', function () {
    // Show profile
})->middleware('[2]')->name('[3]');
Drag options to blanks, or click blank then click option'
A/profile
Bauth
Cprofile.show
D/dashboard
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong URL or middleware name.
Confusing route name with URL.