Get Current Logged in User Data in Laravel

Hello Artisan, in this example tutorial i will show you how to get logged in user data in laravel. You know that when we create a user profile page then we need current logged in user data.

In laravel we can do in a very simple way. We can  do it using Auth facades and auth() helper in laravel to get current logged in user data. I willl show you those two example with code.

From this tutorial you can learn. how to display user profile after login in laravel. Let's see how we can get current logged in user data in Laravel.

Laravel logged in user data with Auth facades:

$user = Auth::user();
   
  
var_dump($user->id);
  
var_dump($user->name);
  
var_dump($user->email);

 

Laravel logged in user data with Auth helper:

$user = auth()->user();
  
  
var_dump($user->id);
  
var_dump($user->name);
  
var_dump($user->email);

 

To get current user id in controller in Laravel, just use:

$id  = Auth::id();

 

Hope it can help you to create a profile page in Laravel.

 

Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js