Documentation Index
Fetch the complete documentation index at: https://kawax.biz/llms.txt
Use this file to discover all available pages before exploring further.
What is authentication?
Authentication is the process of verifying who a user is. In a web application, this typically means accepting an email address and password, verifying the credentials against the database, and then storing user identity in the session for subsequent requests. Laravel’s authentication system is built around two concepts:- Guards — define how users are authenticated per request. The default
sessionguard uses the session and cookies to maintain state. - Providers — define how users are retrieved from storage. The default provider uses Eloquent.
The authentication configuration file is
config/auth.php. For most applications the defaults work without any changes.Setting up authentication with a starter kit
The fastest way to add authentication to a new application is to choose a starter kit when runninglaravel new. It scaffolds login, registration, password reset, and email verification automatically.
Create a new application
Run the installer and choose a starter kit when prompted:Choose from React, Vue, Livewire, or Svelte depending on your preferred frontend stack.
Run migrations
Confirm your database settings in This creates the
.env, then run:users table along with the other default tables.| Feature | URL |
|---|---|
| Registration | /register |
| Login | /login |
| Password reset | /forgot-password |
| Email verification | /email/verify |
| Profile settings | /settings/profile |
The Auth facade
Use theAuth facade to work with the authenticated user in any part of your application.
Retrieving the current user
Request object:
Checking authentication status
Auth::check() returns true if a user is logged in:
@auth and @guest directives:
Protecting routes
Apply theauth middleware to any route that requires authentication:
/login automatically.
Protect multiple routes at once with a group:
Guest-only routes
Use theguest middleware to redirect already-logged-in users away from pages like login and registration:
Manual authentication
If you’re not using a starter kit, you can authenticate users manually withAuth::attempt():
Auth::attempt() accepts an array of credentials and automatically compares the password against its stored hash — pass the plain-text password directly.
To support “remember me” functionality, pass true as the second argument:
Even when building authentication from scratch, review how the starter kit implements it. It’s a solid reference for secure implementation.
Logging out
CallAuth::logout() and then invalidate the session and regenerate the CSRF token:
Quick reference
| Task | How |
|---|---|
| Add authentication quickly | Use a starter kit (laravel new) |
| Get the current user | Auth::user() / $request->user() |
| Check login status | Auth::check() |
| Protect a route | ->middleware('auth') |
| Log in manually | Auth::attempt($credentials) |
| Log out | Auth::logout() |
Next steps
Starter kits
Explore the available starter kits and learn how to customise them.