0
0
Laravelframework~10 mins

Global 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 register a global middleware in Laravel's HTTP kernel.

Laravel
protected $middleware = [
    \App\Http\Middleware\TrustProxies::class,
    [1],
];
Drag options to blanks, or click blank then click option'
A\App\Http\Middleware\Authenticate::class
B\App\Http\Middleware\RedirectIfAuthenticated::class
C\App\Http\Middleware\CheckForMaintenanceMode::class
D\App\Http\Middleware\VerifyCsrfToken::class
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing middleware meant for route groups instead of global middleware.
Confusing authentication middleware with maintenance mode middleware.
2fill in blank
medium

Complete the code to add a custom global middleware class named LogRequests.

Laravel
protected $middleware = [
    [1],
];
Drag options to blanks, or click blank then click option'
A\App\Http\Middleware\VerifyCsrfToken::class
B\App\Http\Middleware\Authenticate::class
C\App\Http\Middleware\RedirectIfAuthenticated::class
D\App\Http\Middleware\LogRequests::class
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to add the ::class suffix.
Adding middleware to the wrong property like $routeMiddleware.
3fill in blank
hard

Fix the error in the middleware registration by completing the missing part.

Laravel
protected $middleware = [
    \App\Http\Middleware\[1]::class,
];
Drag options to blanks, or click blank then click option'
ATrustProxies
BLogRequests
CAuthenticate
DRedirectIfAuthenticated
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing middleware that is usually route-specific instead of global.
Using middleware names that do not exist in the default Laravel setup.
4fill in blank
hard

Fill both blanks to correctly add two global middleware classes: CheckForMaintenanceMode and ValidatePostSize.

Laravel
protected $middleware = [
    [1],
    [2],
];
Drag options to blanks, or click blank then click option'
A\App\Http\Middleware\CheckForMaintenanceMode::class
B\App\Http\Middleware\Authenticate::class
C\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class
D\App\Http\Middleware\RedirectIfAuthenticated::class
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing route middleware with global middleware.
Forgetting to include the full namespace.
5fill in blank
hard

Fill all three blanks to create a global middleware array with TrustProxies, CheckForMaintenanceMode, and ValidatePostSize.

Laravel
protected $middleware = [
    [1],
    [2],
    [3],
];
Drag options to blanks, or click blank then click option'
A\App\Http\Middleware\Authenticate::class
B\App\Http\Middleware\CheckForMaintenanceMode::class
C\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class
D\App\Http\Middleware\TrustProxies::class
Attempts:
3 left
💡 Hint
Common Mistakes
Using middleware classes that are not global.
Incorrect namespace or missing ::class.