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 .
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
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.
Be the first to know about releases and tutorial news and solutions.
We care about your data in our privacy policy.
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.
Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides