0
0
Laravelframework~5 mins

Registering middleware in Laravel - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is middleware in Laravel?
Middleware is a way to filter HTTP requests entering your application. It acts like a gatekeeper that can inspect, modify, or reject requests before they reach your routes or controllers.
Click to reveal answer
beginner
How do you register a global middleware in Laravel?
You add the middleware class to the $middleware array inside the app/Http/Kernel.php file. This makes it run on every HTTP request automatically.
Click to reveal answer
beginner
Where do you register route middleware in Laravel?
Route middleware are registered in the $routeMiddleware array inside app/Http/Kernel.php. You give each middleware a key name to use in routes or controllers.
Click to reveal answer
beginner
How do you apply middleware to a specific route in Laravel?
You use the middleware method on the route definition, like Route::get('/profile', 'ProfileController@index')->middleware('auth'); This runs the 'auth' middleware only for that route.
Click to reveal answer
beginner
What is the difference between global and route middleware in Laravel?
Global middleware runs on every HTTP request automatically. Route middleware runs only on routes or groups where you explicitly apply them.
Click to reveal answer
Where do you register global middleware in Laravel?
AIn the $routeMiddleware array inside app/Http/Kernel.php
BIn the config/app.php file
CIn the routes/web.php file
DIn the $middleware array inside app/Http/Kernel.php
How do you assign a middleware to a specific route?
AWrite it inside the controller constructor
BUse the middleware() method on the route definition
CAdd it to the $routeMiddleware array only
DAdd it to the $middleware array
What is the purpose of the $routeMiddleware array?
ATo list all middleware classes in the project
BTo register middleware that runs on every request
CTo register middleware that can be applied to specific routes by name
DTo configure middleware priority
If you want middleware to run on every HTTP request, where should you register it?
AIn the $middleware array
BIn the $routeMiddleware array
CIn the routes file
DIn the controller
Which file is the main place to register middleware in Laravel?
Aapp/Http/Kernel.php
Broutes/web.php
Cconfig/middleware.php
Dapp/Providers/AppServiceProvider.php
Explain how to register and apply middleware to a route in Laravel.
Think about the $routeMiddleware array and route methods.
You got /3 concepts.
    Describe the difference between global and route middleware in Laravel.
    Consider where each type is registered and when it runs.
    You got /4 concepts.