Laravel 5.5 get current login user detail

Laravel is the object-oriented PHP Framework. Laravel provides awesome auth functionality. Using Auth we can perform all user related operations. Today we are learning how to get the current login user detail using Auth.

Laravel provides Helper and Facades for getting current login user detail using Auth. let’s see both ways how we can get the current login user detail.

Using Facades we can get the current login user detail like

use Illuminate\Support\Facades\Auth;

// Get the currently authenticated user
$user = Auth::user();

$userId = $user->id;
$userEmail = $user->email;
$userName = $user->name;

echo '<pre>';
print_r($user);

// Get the currently authenticated user's ID...
$id = Auth::id();

Using Helper we can get the current login user detail like

// Get the currently authenticated user
$user = auth()->user(); $userId = $user->id; $userName = $user->name; $userEmail = $user->email; echo '<pre>'; print_r($user);

If you face any issue with getting the current login detail write the comment below.

Always welcome for the best suggestion or improvement write the comment.

Published by

Sherya

Hello there, I am developer currently working with the company at Pune and part-time freelancer. Always I welcome a new opportunity.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s