Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get User in Laravel 5.4 Controller constructor

I have Laravel 5.4 Base Controller which should share along children Controllers some common data depending on current Authenticated user.

I was Trying to get it like

public function __construct(ValidationFactory $validation)
{
    $this->middleware(array('auth', 'lockscreen'));
    var_dump(\Auth::user());
    die;  
}

this do not works.

like image 719
fefe Avatar asked Jun 30 '17 15:06

fefe


1 Answers

private $userId;

public function __construct()
{
   $this->middleware(function ($request, $next) {
        $this->userId = Auth::user()->id;
        return $next($request);
    });
}
like image 137
Ijaz Ahmed Bhatti Avatar answered Sep 28 '22 00:09

Ijaz Ahmed Bhatti