How to get logged in user data into Laravel controller

Anand Maurya picture Anand Maurya · Jul 22, 2017 · Viewed 30.6k times · Source

I am working on laravel 5.4, i have used the auth for user login at client side,now i want the logged in user details at the Controller,

view side by writing below code i got that:

{{ Auth::user()->name }} // this works on view page only.

Suggest me the library files with the code. I want to display some user data like name,age,dob,etc after logged in.

Answer

RAUSHAN KUMAR picture RAUSHAN KUMAR · Jul 22, 2017

The laravel Auth Facade is used to get the autheticated user data as

$user = Auth::user();
print_r($user);

This will work in your controller and view both, but you have to include it as

use Illuminate\Support\Facades\Auth;