Skip to main content

What is authentication

Authentication is the mechanism for confirming “who” the user accessing your application is. In web applications, you receive an email and password via a login form, and if they are correct, save the user’s information in the session. On subsequent requests, that session is used to identify the user. Laravel’s authentication features are built around two concepts: “guards” and “providers.”
  • Guards define how the user is authenticated on each request. The default is the session guard, which uses sessions and cookies to manage state.
  • Providers define how users are retrieved from your database. The default uses Eloquent.
The authentication configuration file is config/auth.php. The default configuration works for most web applications as-is.

Authentication with starter kits

In Laravel, by choosing a starter kit when creating your application with laravel new, authentication features like login, registration, and password reset are automatically built for you. This is the most recommended approach.
1

Create the application

Create your application with the Laravel installer. It will prompt you to choose a starter kit during setup.
You can select React, Vue, Livewire, or Svelte as your starter kit. Choose one that matches your team’s technology stack.
2

Install frontend dependencies

3

Prepare the database

Verify the database configuration in your .env file, then run migrations.
The initial migrations, including the users table, are applied.
4

Start the development server

Visit http://localhost:8000 in your browser, and you’ll see “Register” and “Log in” links in the navigation. Visit /register and try registering a user.
Once you have the starter kit, the following features are available right away.
All the code generated by the starter kit (controllers, routes, views) lives inside your own application. You can freely modify and customize it.

Available starter kits

React

Build a modern SPA using React 19, TypeScript, Tailwind, and shadcn/ui. By using Inertia, you can use a React frontend while retaining server-side routing.

Vue

Uses Vue Composition API, TypeScript, Tailwind, and shadcn-vue. Like React, it uses Inertia to integrate with the server.

Livewire

Uses Livewire to build dynamic UIs entirely in PHP. Ideal for teams that primarily work with Blade templates or want to avoid JavaScript frameworks. Includes the Flux UI component library.

Svelte

Uses Svelte 5, TypeScript, Tailwind, and shadcn-svelte. Combines with Inertia to build a modern SPA.

The Auth facade

Using the Auth facade, you can get information about the currently authenticated user and check the authentication state.

Getting the authenticated user

In a controller, you can also get the user from the Request object.

Checking authentication state

Auth::check() returns true or false depending on whether the user is logged in.
In Blade templates, the @auth and @guest directives are convenient.

Protecting routes

To create routes that only authenticated users can access, use the auth middleware.
An unauthenticated user attempting access is automatically redirected to /login. To protect multiple routes at once, use groups.
Forgetting to add the auth middleware allows unauthenticated users to access your routes. Always apply it to routes that require protection.

Guest-only routes

Use the guest middleware to redirect users who are already logged in. Applying it to login and registration pages redirects already-logged-in users to the dashboard.

Manual authentication

To implement login manually without using a starter kit, use Auth::attempt().
Pass an array of credentials as the first argument to Auth::attempt(). The password is automatically compared against the hash, so pass it in plaintext. To implement “remember me” functionality, pass true as the second argument.
Even when implementing manual authentication, we recommend referring to the starter kit’s code. It’s a great reference for a secure implementation.

Logout

To log a user out, call Auth::logout(). It’s a best practice to also invalidate the session and regenerate the CSRF token.
Use POST for the route.
In Blade templates, use a form to send a POST request.

Summary

Next steps

Middleware

Learn about how the auth middleware works and how to build your own middleware.
Last modified on July 13, 2026