If you try to get Auth::user() inside Laravel -> Controller -> __construct, it will return null.
The reason is middleware is not running yet. Constructor always are created before the middleware.
But, hopefully there is simple way to do it using middleware:
public function __construct()
{
$this->middleware(function ($request, $next) {
$user = Auth::user();
return $next($request);
});
}
How to get Auth user info on Laravel Controller construct
#Laravel Auth
#get Auth info on construct
#laravel construct auth
#Laravel controller auth
#how to get auth info
Rashad Mirza
Dec 5, 2020
Rashad Mirza
Lead senior developer, who spends his day by developing, tutoring and learning new languages
DEVELOPING
Since 2004
More posts
#Laravel
#Laravel Migration
#Laravel database
#Laravel Textarea
#nl2br
#Laravel blade textarea
#Textarea html laravel
#Laravel
#Laravel DebugBar
#Laravel testing
#Vue
#Vue.js
#Vuex
#Make Vuex state persistent
#Php artisan
#Laravel
#Laravel commands
#Migration