Laravel 5 get current authenticated user?

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.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.
DMCA.com Protection Status