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 create a new middleware in Laravel?
You use the artisan command: <code>php artisan make:middleware MiddlewareName</code>. This creates a new middleware class in the <code>app/Http/Middleware</code> directory.Click to reveal answer
beginner
What method must you implement in a Laravel middleware class?
You must implement the
handle method. It receives the request and a closure to pass the request to the next middleware or controller.Click to reveal answer
intermediate
How do you register middleware so Laravel uses it?
You register middleware in
app/Http/Kernel.php. You can add it to the $middleware array for global use or to $routeMiddleware for specific routes.Click to reveal answer
beginner
How do you apply middleware to a route in Laravel?
You apply middleware by adding the
middleware method to a route or group, like Route::get('/home', ...)->middleware('auth');.Click to reveal answer
Which artisan command creates a new middleware in Laravel?
✗ Incorrect
The correct command is
php artisan make:middleware MiddlewareName.Where do you register route-specific middleware in Laravel?
✗ Incorrect
Route-specific middleware is registered in
app/Http/Kernel.php inside the $routeMiddleware array.What does the
handle method in middleware do?✗ Incorrect
The
handle method processes the incoming request and decides whether to pass it along or reject it.How do you apply middleware to a route in Laravel?
✗ Incorrect
Middleware is applied to routes using the
middleware method, e.g., Route::get(...)->middleware('auth').What is the main purpose of middleware in Laravel?
✗ Incorrect
Middleware filters HTTP requests and can modify or block them before they reach the controller.
Explain how to create and register a middleware in Laravel and how to apply it to a route.
Think about the steps from creation to usage in routes.
You got /4 concepts.
Describe the role of the handle method inside a Laravel middleware class.
Focus on what happens inside the handle method.
You got /4 concepts.