Sonu's avatar
Level 3

How to Get Name Of Authenticated Users After Login

How can i get the name id and email etc of authenticated user After login in laravel 5

0 likes
7 replies
RomainLanz's avatar

You can use the Auth facade.

Auth::user()->id // or Auth::id()
Auth::user()->email;
1 like
richard's avatar

If you want to fetch the user's fullname in a proper way instead of doing Auth::user()->firstname.' '.Auth::user()->lastname, you can put this method on your User model.

public function getNameAttribute()
{
    return $this->firstname.' '.$this->lastname; 
}

then display user's name as Auth::user()->name;

1 like
bestmomo's avatar

There is also the helper :

auth()->user()->someÀttribute
``
cconey's avatar

You can also pull the auth object off of any request object that you inject like so:

public function store(Request $request) {
    $request->user()->name
    // Do other things
}

Please or to participate in this conversation.