0
0
Laravelframework~10 mins

Middleware groups 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 middleware group named 'web' in Laravel.

Laravel
protected $middlewareGroups = [
    'web' => [
        [1]
    ],
];
Drag options to blanks, or click blank then click option'
A'auth',
B'api',
C'throttle:60,1',
D\App\Http\Middleware\EncryptCookies::class,
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'auth' which is for authentication, not cookie encryption.
Confusing 'api' group middleware with 'web' group.
2fill in blank
medium

Complete the code to add the 'throttle' middleware to the 'api' middleware group.

Laravel
protected $middlewareGroups = [
    'api' => [
        [1]
    ],
];
Drag options to blanks, or click blank then click option'
A'web',
B'auth',
C'throttle:60,1',
D'EncryptCookies',
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'auth' which is for authentication, not rate limiting.
Adding 'web' middleware inside 'api' group.
3fill in blank
hard

Fix the error in the middleware group definition by completing the missing middleware name.

Laravel
protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\[1]::class,
    ],
];
Drag options to blanks, or click blank then click option'
AAuthenticate
BEncryptCookies
CVerifyCsrfToken
DThrottleRequests
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Authenticate' which is for auth, not cookie encryption.
Using 'ThrottleRequests' which is for rate limiting.
4fill in blank
hard

Fill both blanks to add 'auth' and 'verified' middleware to the 'web' group.

Laravel
protected $middlewareGroups = [
    'web' => [
        [1],
        [2],
    ],
];
Drag options to blanks, or click blank then click option'
A'auth',
B'verified',
C'throttle:60,1',
D'guest',
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'guest' which is for unauthenticated users.
Adding 'throttle' which is for API rate limiting.
5fill in blank
hard

Fill all three blanks to define a custom middleware group 'admin' with 'auth', 'verified', and 'is_admin'.

Laravel
protected $middlewareGroups = [
    'admin' => [
        [1],
        [2],
        [3],
    ],
];
Drag options to blanks, or click blank then click option'
A'auth',
B'verified',
C'is_admin',
D'guest',
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'guest' which is for unauthenticated users.
Missing the 'is_admin' middleware for admin access.