construct Archives - 7-Views

How to get the current user in a __construct method of controller

Posted by
January 31, 2021

This issue arises because the controller __construct method executes before any middleware. so it returns null when we call auth()->user() So the solution of the issue is, inside your Controller __construct method call this. public function __construct() { $this->middleware(function ($request, $next) { dump(auth()->user()); return $next($request); }); }  

read more