Monday, March 2, 2020

How to get current user details in Laravel 6?


How to get current user details in Laravel 6?

Today I want to add a little tutorial on how to get current user details in the Laravel 6 application. I'll show you how to get the current user ID, current username and email address of the current user in the Laravel 6 application. You can simply call up the current login user ID in the Laravel 6 controller. The current user details is retrieved using authentication in Laravel 6.

The most important thing is that when working with authentication, I know how to get my current login information. So I'll give you an example of how to get current user details in Laravel 6. Laravel 6 offers authentication for authentication. With Auth, you can easily get current user credentials with email, name, and identification.

Let's see that I've added two ways to get current user details in the Laravel 6 application.


Auth Helper:


Here we to get current user details with auth () in Laravel 6.

$user = auth()->user();

  

  

var_dump($user->id);

  

var_dump($user->name);

  

var_dump($user->email);


Output:


12

John

myitbuddies11@gmail.com



Auth Facade:


Here we receive current user details with Auth Facade in Laravel 6.

$user = Auth::user();

   

  

var_dump($user->id);

  

var_dump($user->name);

  

var_dump($user->email);


Output:


12

John

myitbuddies11@gmail.com

I hope this could help you ...



0 comments:

Post a Comment

Please don't enter any spam link in the comment box.