Recall & Review
beginner
What is route middleware in Laravel?
Route middleware is a way to filter HTTP requests entering your application. It runs code before or after a route is executed to check conditions like authentication or logging.
Click to reveal answer
beginner
How do you apply middleware to a route in Laravel?
You add middleware to a route using the
middleware() method in the route definition, for example: Route::get('/dashboard', fn() => 'Dashboard')->middleware('auth');Click to reveal answer
intermediate
What is the difference between global middleware and route middleware?
Global middleware runs on every HTTP request to your app. Route middleware runs only on specific routes you assign it to.
Click to reveal answer
intermediate
How do you create a custom route middleware in Laravel?
Use
php artisan make:middleware MiddlewareName to create it. Then add your logic in the handle method and register it in app/Http/Kernel.php under $routeMiddleware.Click to reveal answer
intermediate
What happens if a middleware returns a response before the route runs?
The middleware stops the request from reaching the route and sends the middleware's response back to the browser. This is useful for blocking unauthorized access.
Click to reveal answer
Which method is used to assign middleware to a Laravel route?
✗ Incorrect
The correct method to assign middleware to a route is middleware().
Where do you register custom route middleware in Laravel?
✗ Incorrect
Custom route middleware must be registered in the $routeMiddleware array inside app/Http/Kernel.php.
What is the main purpose of route middleware?
✗ Incorrect
Route middleware filters requests and controls access to routes.
If middleware returns a response early, what happens next?
✗ Incorrect
Middleware can stop the request and send its own response without running the route.
Which artisan command creates a new middleware class?
✗ Incorrect
Use php artisan make:middleware to create a new middleware class.
Explain how route middleware works in Laravel and how you apply it to a route.
Think about how you protect pages like a dashboard.
You got /4 concepts.
Describe the steps to create and register a custom route middleware in Laravel.
Focus on creation, coding, registration, and usage.
You got /4 concepts.