D
D
Dasha2015-12-22 21:16:03
Laravel
Dasha, 2015-12-22 21:16:03

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

1 answer(s)
A
Alexey Ukolov, 2015-12-22
@bizzi

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.

laravel.com/docs/5.2/middleware

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question