0
0
Laravelframework~5 mins

Global middleware in Laravel - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is global middleware in Laravel?
Global middleware runs on every HTTP request to your application. It applies to all routes automatically without needing to be assigned individually.
Click to reveal answer
beginner
Where do you register global middleware in a Laravel app?
You register global middleware in the app/Http/Kernel.php file inside the $middleware array.
Click to reveal answer
intermediate
How does global middleware differ from route middleware?
Global middleware runs on every request automatically. Route middleware runs only on routes or groups where you assign it explicitly.
Click to reveal answer
beginner
Give an example of a common global middleware in Laravel.
The CheckForMaintenanceMode middleware is often global. It checks if the app is in maintenance mode and blocks requests accordingly.
Click to reveal answer
intermediate
Why use global middleware instead of route middleware?
Use global middleware for tasks that must happen on every request, like security checks or trimming input. It ensures consistency without repeating assignments.
Click to reveal answer
Where do you add global middleware in Laravel?
AIn the $middleware array of app/Http/Kernel.php
BIn the routes/web.php file
CIn the config/app.php file
DIn the middleware folder only
What happens if you add middleware to the $middleware array?
AIt runs only on web routes
BIt runs only on API routes
CIt runs on every HTTP request
DIt runs only when assigned to a route
Which middleware type requires manual assignment to routes?
AGlobal middleware
BRoute middleware
CKernel middleware
DAutomatic middleware
Why might you avoid putting heavy tasks in global middleware?
ABecause it runs on every request and can slow down the app
BBecause it only runs once
CBecause it does not run on API routes
DBecause it is not secure
Which of these is a typical use for global middleware?
AAssigning roles to users
BLogging user activity only on admin pages
CApplying CSRF protection only on forms
DChecking maintenance mode
Explain what global middleware is in Laravel and how it is registered.
Think about middleware that always runs no matter the route.
You got /3 concepts.
    Describe the difference between global middleware and route middleware in Laravel.
    Consider when each middleware type runs during a request.
    You got /4 concepts.