Nicholas Kajoh Nicholas Kajoh - 1 month ago 11
PHP Question

How do I make a logged in user object available to all views in Laravel 5.3

I want to be able to get a logged in user's details in my views. E.g

{{ $user->email }}
.

Here's my
Controller.php
:

public $view_data = array();

public function __construct()
{
$this->middleware('auth');
$this->view_data['user'] = Auth::user();
}


$user
in my views return
NULL
. Am I missing something?

Answer

It is already available in all views by default via:

Auth::user()
auth()->user()
Comments