Laravel Get Current Login User Details Example
Hi Developer,
In this tutorial laravel get logged user details using auth. i will show you how to get current login user details in laravel. name, email, created_at, role etc using auth() helper or Auth facade class.
we can easily get auth user data using auth helper in laravel application.
we almost need to get current logged in user data because we need to some restrict to pages or get only login user data so at that time we must need to get logged in user details like id or name.
So, we can get current user details using laravel auth. You can also use simple auth helper or Auth facade. So i will give you both example, you can take any one as you want. So let's see both examples one by one.
Using Helper:
$user = auth()->user();
print($user->id);
print($user->name);
print($user->email);
Using Facade:
$user = auth()->user();
print($user->id);
print($user->name);
print($user->email);
It Will help you....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial