Last updated on February 17, 2018
Upon successful login you can get current user details by called Auth::user()
method. It will return null if no user logged in or there is no current user.
On successful login Auth::user()
return value is based on your authentication configuration. If your driver is eloquent then the object return is the class specified by the model settings. generally, it would be User modal.
If your authentication driver is database then the object returned is a generic user. Specifically it’s the Illuminate\Auth\GenericUser class
.
you can access user id or any other columns of user table easily –
Get Current User ID – Auth::User()->id;
Get Current User Email – Auth::User()->email;
Get Current User Name = Auth::User()->name;
That is it.