0

I am using Laravel 5.3 and am having some issues with the authentication.

Prior to me working on this program the developer set it up so all of the controllers that need to authenticated are extended from an account controller class (which extends the base controller etc). The account controller class just runs $this->middleware('auth') which should run the handle method in the authenticate class to check if there is an active session and if not redirect the user to the login page.

The strange thing is that this works for some controllers but not for others even though the controllers are all extended from the same account controller. In the controllers it is not working, it does not seem to even get to the handle method in the authenticate class.

I was wondering if there is something in laravel that specifies what routes to authenticate and i need to define in there or does anyone have any other idea of why this seems to work for some pages and not others even though the controllers are setup the same?

2
  • 2
    Perhaps they extend the parent controller but overload the controller constructor without calling parent::__construct() where the auth middleware is applied. Commented Jan 5, 2017 at 11:00
  • I checked this and they are calling the parent constructor in the same way the controllers that are working normally are. Commented Jan 5, 2017 at 14:31

1 Answer 1

1

You can put a check at Route level like:

Route::group(['middleware' => 'auth'], function () { // All the routes enclosed in this block are protected }); // Put unprotected routes outside the block 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your response. I understand this is the proper laravel way of doing user authorisation so maybe it is best to change my app to do it that way.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.