Laravel Get Auth User ID Example
Feb 03, 2020
hi gusy
In this blog i will explain you can how to get current logged in user in laravel. i will show get current user id in controller, view files. you can user auth() helper and auth facade class to get current user data.
I will show you how to get current user data like id by using laravel .We will give you two way to get current user data using laravel authentication. you can simply get logged in user details in controller or view blade files.
I 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.I always require getting current logged in user data in laravel.
Here the blow example of get auth user id in laravel
Example Using Facade
Now this example is using facade.
$user = Auth::user();
print($user->id);
Example Using Helper
Now this example is using facade.
$user = auth()->user();
print($user->id);
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