I have a private variable in my class that I want to be set to the authenticated user. For some reason, though, I can't get the variable to be set inside of the constructor. Here is what I have so far:
private $user = null;
public function __construct()
{
$this->middleware('auth');
$this->user = Auth::user();
}
public function index()
{
$return['Admin'] = $this->user;
return view('home', compact('return'));
}
The variable $user stays null for some reason though. When I use Auth::user() in place of $this->user though, it works just fine. I have set variables from the constructor multiple times in the past and this is the first time it hasn't worked for me. Any help would be appreciated.