@Sinnbeck are you sure you have an admin account in your user database?
Auth::guard('admin')->user() returns NULL
hi. i logged in with the attempt (admin guard) method and a session is also created. but in my controller Auth::user , return null .
I've dedicated Middleware "auth:admin" to that Route. I just created a provider named admin and guard admin, do I need to make other settings? Thanks
you cannot obtain the authenticated user within the __construct() method. Controllers are initiated before the authentication is performed.
Test from within a controller method.
It is possible to access the user model within the constructor via a middleware. If you needed to setup some controller attributes, you can do it like;
public function __construct()
{
$this->middleware(function ($request, $next) {
$this->user = Auth::user();
return $next($request);
});
}
The middleware is registered when the constructor runs, and then the code inside the callback is executed when middlewares are executed later.
Please or to participate in this conversation.