How can we check the logged-in user info in Laravel?

User() function is used to get the logged-in user

Example

if(Auth::check()){
$loggedIn_user=Auth::User();
dd($loggedIn_user);
}

In Laravel, you can access the logged-in user’s information using the Auth facade or the auth() helper function. Here’s how you can do it:

Using Auth Facade:

php
use Illuminate\Support\Facades\Auth;

$user = Auth::user();

if ($user) {
// User is logged in
// Access user properties like $user->id, $user->name, etc.
} else {
// User is not logged in
}

Using auth() helper function:

php
$user = auth()->user();

if ($user) {
// User is logged in
// Access user properties like $user->id, $user->name, etc.
} else {
// User is not logged in
}

Both methods will return the currently authenticated user’s instance if a user is logged in, or null if no user is authenticated. You can then access the user’s information such as their ID, name, email, etc., through the returned user object.