Naxon
3 years ago

Can't call Auth::user() on controller's constructor

Posted 3 years ago by Naxon

I'm trying to check if the user has permission to a certain model. Up until now (with Laravel 5.2), I added this code at the constructor:

public function __construct()
{
    if (!Auth::user()->hasPermission('usergroups')) {
        abort(404);
    }
}

Now, after upgrading to Laravel 5.3,Auth::user() returns null when being called from the controller's constructor. If I call it within any other method of the class, it returns the currently logged in user.

Any Ideas why?

Please sign in or create an account to participate in this conversation.