📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Laravel Framework Authentication

Authentication

6 min read Quiz at the end
Implement login and logout using Laravel Breeze scaffolding or the Auth facade directly.

Authentication

// Laravel Breeze (simple auth scaffolding)
composer require laravel/breeze --dev
php artisan breeze:install blade
php artisan migrate && npm run dev

// Manual auth
use IlluminateSupportFacadesAuth;

if (Auth::attempt(["email" => $email, "password" => $pass])) {
    $request->session()->regenerate();
    return redirect()->intended("dashboard");
}

Auth::logout();
$request->session()->invalidate();
$request->session()->regenerateToken();

// Get current user
$user = Auth::user();
$user = auth()->user();
$id   = auth()->id();

// Protect routes
Route::middleware("auth")->group(function () {
    Route::get("/dashboard", [DashboardController::class, "index"]);
});

// Protect controllers
public function __construct() {
    $this->middleware("auth");
    $this->middleware("auth")->only(["create", "store"]);
}
Topic Quiz · 3 questions

Test your understanding before moving on

1. Which package provides simple auth scaffolding?
💡 Laravel Breeze is the lightweight auth scaffolding with Blade/React/Vue options.
2. Which facade handles authentication?
💡 The Auth facade provides login, logout, check, user, id, and attempt methods.
3. What does Auth::attempt() return?
💡 Auth::attempt() returns true if credentials are valid and user is logged in.