Recall & Review
beginner
What is controller middleware in Laravel?
Controller middleware in Laravel is a way to filter HTTP requests entering your application by running code before or after a controller action. It helps manage tasks like authentication, logging, or input validation.
Click to reveal answer
beginner
How do you apply middleware to a Laravel controller?
You apply middleware in a controller by calling the
$this->middleware('middlewareName') method inside the controller's constructor. This runs the middleware on all or selected controller methods.Click to reveal answer
intermediate
How can you restrict middleware to only certain methods in a controller?
Use the
only or except options when applying middleware, like $this->middleware('auth')->only(['index', 'show']) to run middleware only on those methods.Click to reveal answer
beginner
What happens if middleware denies a request in Laravel?
If middleware denies a request, it usually returns a response like a redirect or error before the controller method runs, stopping further processing.
Click to reveal answer
intermediate
Can you apply multiple middleware to a single controller in Laravel?
Yes, you can apply multiple middleware by passing an array to
$this->middleware(['auth', 'verified']). They run in the order listed.Click to reveal answer
How do you add middleware to a Laravel controller?
✗ Incorrect
Middleware is added inside the controller constructor using $this->middleware('name').
Which method restricts middleware to specific controller methods?
✗ Incorrect
You can use both only() to include and except() to exclude methods when applying middleware.
What does middleware do if it blocks a request?
✗ Incorrect
Middleware returns a response like redirect or error before the controller method runs.
Can you apply multiple middleware to one controller?
✗ Incorrect
Multiple middleware can be applied by passing an array to $this->middleware(['one', 'two']).
Where is controller middleware typically defined?
✗ Incorrect
Middleware is defined inside the controller constructor using $this->middleware().
Explain how to apply middleware to only some methods of a Laravel controller.
Think about how to include or exclude methods when calling $this->middleware.
You got /4 concepts.
Describe what happens when middleware denies a request in Laravel.
Middleware can stop the request before it reaches the controller.
You got /3 concepts.