Laravel 7/6 Get Current User Example
Today, i want to add small tutorial for how to get current user data in laravel 7/6 application. i will show you how to get current user id, current user name, current user email address in laravel 7/6 app. you can easily get current login user id in controller of laravel 7/6. we will get current user data using auth in laravel 7/6.
It's most important thing is when you are working with authentication then you know how to get my current login user details. so i will give you example how you can get current user data in laravel 7/6. laravel 7/6 provide auth for authentication, using auth you can easily get current login user data with email, name and id.
So, let's see i added two way to getting current user data in laravel 6 application.
Auth Helper:
Here, we will get current user data using auth() in laravel 6.
$user = auth()->user();
var_dump($user->id);
var_dump($user->name);
var_dump($user->email);
Output:
12
Hardik
itsolutionstuff@gmail.com
Auth Facade:
Here, we will get current user data using Auth Facade in laravel 6.
$user = Auth::user();
var_dump($user->id);
var_dump($user->name);
var_dump($user->email);
Output:
12
Hardik
itsolutionstuff@gmail.com
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Send Email Notification in Laravel?
- Laravel 7/6 Import Export Excel & CSV File Tutorial
- Laravel 7/6 Dropzone Image Upload Tutorial
- Laravel 7/6 REST API with Passport Tutorial
- Laravel 6 Email Verification Tutorial
- Laravel 7/6 Multi Auth (Authentication) Tutorial
- Laravel 6 File Upload Tutorial Example
- How to Send Mail in Laravel 6?
- Laravel 6 Authentication Tutorial