Laravel ge logged in user details example; In this tutorial you will learn how to get logged in user details in laravel application.
In Laravel we can get current login user data both way one using auth helper and another Auth facade. In below example we will show you how to simply get current logged in user data in controller or blade view files.
laravel get auth user Data in Controller
Using the auth() helper you can get auth user details easily, it will return object of users details.
Get Auth User Data using helper
$authUser = auth()->user();
echo '<pre>'; print_r($authUser); die;
Get Auth User ID using helper
$authUserId = auth()->user()->id;
echo '<pre>'; print_r($authUserId); die;
The laravel facade also return logged in user data same as helper.
Get Logged User Data using facade
$authUser = Auth::user();
echo '<pre>'; print_r($authUser); die;
Get Logged User ID using facade
$authId = Auth::id();
echo '<pre>'; print_r($authId); die;
Laravel get Loggedin user Data in Blade
For gettting logged in user details in laravel blade view file is same as getting controller file. You just need to do this:
@php
$authUser = Auth::user(); // return logged in user details
$authId = Auth::id(); //return current loggedin user id
@endphp
I hope this example works for you.