laravel get user email code example

Example 1: current user laravel

$user = auth()->user();  print($user->id);print($user->name);print($user->email);

Example 2: laravel auth user_id

$userId = Auth::id();

Example 3: laravel get auth user id

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

Example 4: laravel using username instead of email

All we need is add a method in app/Http/Controllers/Auth/LoginController.php:

/**
 * Get the login username to be used by the controller.
 *
 * @return string
 */
public function username()
{
    return 'username';
}

Tags:

Misc Example