Laravel 8 Get Current Logged in User Data Example
Hi Artisan,
If you need to see example of laravel 8 get current logged in user id. let’s discuss about how to get current user id in laravel 8. you'll learn laravel 8 get current user id. this example will help you get current user data laravel 8. you will do the following things for get current user email in laravel 8.
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 8. laravel 8 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 8 application.
Auth Helper:
Here, we will get current user data using auth() in laravel 8.
$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 8.
$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
- Laravel 8 Socialite Login with Google Account Example
- Laravel 8 Autocomplete Search from Database Example
- Laravel 8 Inertia JS CRUD with Jetstream & Tailwind CSS
- Laravel 8 Queue Step by Step Tutorial Example
- Laravel 8 Livewire CRUD with Jetstream & Tailwind CSS
- Laravel 8 Send Mail using Gmail SMTP Server
- Laravel 8 PDF | Laravel 8 Generate PDF File using DomPDF
- Laravel 8 Database Seeder Tutorial Example
- Laravel 8 Auth with Livewire Jetstream Tutorial
- Laravel 8 Authentication using Jetstream Example
- Laravel 8 Multiple Image Upload Tutorial