How to Get Logged in User Data in Laravel

  Aug 2023
  ITSolutionsGuides
  Category: Laravel
How to Get Logged in User Data in Laravel

Hi Developers,

While developing a dynamic website and admin panel we need to display the current user name and data and also we need current user data to perform some functions to verify whether the current logged user is allowed or restricted from accessing some features , also to tract the users activity .

Get Logged User

To get current Logged user there are two methods auth() Helper function & Auth Facade

//using auth() Helper function
$user = auth()->user();
print_r($user);     // Display complete current logged user Data
$id = auth()->user()->id;   
print_r($id);        // Display current logged user ID



//Using Auth Facade
$user = Auth::user();
print_r($user);     // Display complete current logged user Data
$id = Auth::user()->id;   
print_r($id);        // Display current logged user ID

Display Logged User in Blade File

To display Logged User in Blade File using two methods auth() Helper function & Auth Facade
are usually done by enclosing the data inside double curly braces {{}}

//using auth() Helper function

{{ auth()->user()->id }} 




//Using Auth Facade

{{ Auth::user()->id }}

We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.

Subscribe for NewsLetter

Be the first to know about releases and tutorial news and solutions.

We care about your data in our privacy policy.

ITSolutionsGuides

ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.

Contact US

ITSolutionsGuides, provide users with an easy-to-use form to reach out for support or inquiries.

whatsapp  gmail  instagram-new--v1  facebook-circled  twitter-circled  linkedin  github  pinterest 

Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides