Answer the question
In order to leave comments, you need to log in
How to apply authentication to the entire controller?
I started to make an application on laravel 5 and a question arose about authentication.
Here I have a controller, I want only authenticated users to have access to its actions.
Inserting if( Auth::check() ) {....}
into each action
seems outrageous to me. Before that, I made an application on laravel 4 and there in each controller I wrote
public function __construct()
{
$this->beforeFilter(function()
if( Auth::check() ) {....}
}
And here you can just figure it out with authentication?
Answer the question
In order to leave comments, you need to log in
HTTP middleware provide a convenient mechanism for filtering HTTP requests entering your application. For example, Laravel includes a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware will redirect the user to the login screen. However, if the user is authenticated, the middleware will allow the request to proceed further into the application.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question