4

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.

Leo
  • 7,274
  • 5
  • 26
  • 48

2 Answers2

2

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

Conor Mancone
  • 1,940
  • 16
  • 22
1

Use the helper function auth()->check() and add

$this->middleware('auth') to the function __construct() method.

Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43