Reputation: 7420
I have created the routes and views needed for authentication using one simple command:
php artisan make:auth
Everything works fine login and register sections. However when I go to my controller's constructor to check if the user its logged in I always get false response; even though the user its logged in!
public function __construct()
{
dd(Auth::check());
}
Any idea?! And yes I did use Auth;
at the top.
Upvotes: 4
Views: 4952
Reputation: 3756
Use the helper function auth()->check()
and add
$this->middleware('auth')
to the function __construct()
method.
Upvotes: 1
Reputation: 2030
Middleware (and therefore setting the logged in user) don't happen until after the controller constructor. See this related question/answer for more details:
Laravel 5 Auth is non object in Controller construct
Upvotes: 2