Support the ongoing development of Laravel.io →
Authentication Architecture
Last updated 2 years ago.
0

First, this can't works fine, because return finishes the method, so it will be only redirected. And what do you mean with filter ?

Last updated 2 years ago.
0

SzkolaWEB said:

First, this can't works fine, because return finishes the method, so it will be only redirected. And what do you mean with filter ?

The first return is only executed if Auth::check() returns true. Otherwise, the second return is executed.

By filter, he's referring to adding a before() filter to check if the user is authenticated and handle the redirect.

behnampmdg3, I think the benefit comes from having the before() filter defined for the entire controller or route group, so it's only defined in one place. For example, if you want to change your flash_notice message, you'd only have to do it in one place, versus modifying every controller action that is protected.

Last updated 2 years ago.
0

I think I am fine without filter for this.

Last updated 2 years ago.
0

The problem is every time you need to check is the User logged in or not, you need to repeat yourself. (Keep it DRY)

It would be better to define a before Filter inside your Controller.

It also getting more and more complicated if you need to check for specific permissions...

Last updated 2 years ago.
0

psychonetic said:

The problem is every time you need to check is the User logged in or not, you need to repeat yourself. (Keep it DRY)

It would be better to define a before Filter inside your Controller.

It also getting more and more complicated if you need to check for specific permissions...

Got it champ

Last updated 2 years ago.
0

Auth is something you will be doing on most actions. So much code can be saved by putting your auth filter on a Route group

Route::group(['before' => 'auth'], function()
{
    //define all routes here that need to be auth'd
});
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.