# Setting up authentication using Laravel Breeze

> Learn how to add authentication to a Laravel app with Breeze, scaffolding registration, login, and a dashboard with php artisan breeze:install.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2023-06-19 | Topics: [Laravel](https://flaviocopes.com/tags/laravel/) | Canonical: https://flaviocopes.com/setting-up-authentication-using-laravel-breeze/

We don’t want random people to come to the website and edit data.

We want people to log in first.

If logged out they will see the list of dogs.

If logged in they will have the ability to edit the list.

Laravel provides us built-in authentication support in the framework.

To make things even easier, it provides [Breeze](https://github.com/laravel/breeze), an application starter kit tool that will create what we need in no time. Breeze scaffolds user registration, login, password reset, profile page, dashboard… and even API authentication. It’s great. For more advanced needs we also have [JetStream](https://jetstream.laravel.com/), but Breeze is easier to set up.

First, create a new Laravel project, so we start from a clean slate.

The first one was named `first`, so to continue the tradition we’ll call this second project `second`:

```shell
composer create-project laravel/laravel second
```

Go into that folder:

```shell
cd second
```

Install breeze using [composer](https://flaviocopes.com/php-composer-packagist/):

```shell
composer require laravel/breeze --dev
```

Now run

```shell
php artisan breeze:install 
```

and pick option 0, “blade”, and pick the default options for the other questions artisan asks you:

![Terminal showing artisan breeze:install command with Blade option selected and default configuration choices](https://flaviocopes.com/images/setting-up-authentication-using-laravel-breeze/1.webp)

Now you can run `php artisan serve` and go to [http://127.0.0.1:8000/](http://127.0.0.1:8000/).

You’ll see the “Log in” and “Register” links:

![Laravel homepage with Log in and Register links in the navigation](https://flaviocopes.com/images/setting-up-authentication-using-laravel-breeze/2.webp)

All the login functionality is working out of the box:

![Login form page with email and password fields and Remember me checkbox](https://flaviocopes.com/images/setting-up-authentication-using-laravel-breeze/3.webp)

![Registration form with Name, Email, Password, and Confirm Password fields](https://flaviocopes.com/images/setting-up-authentication-using-laravel-breeze/4.webp)

Laravel added a _ton_ of resources to achieve this.

Easily days of work for a developer, and it’s battle-tested code which you don’t want to write yourself, as it’s a quite important and needs to be well tested for security issues.

I recommend you take a look at the file structure and compare it to the first project. Lots of new stuff has been added, for example views:

![File explorer showing Laravel project structure with new authentication views and components added by Breeze](https://flaviocopes.com/images/setting-up-authentication-using-laravel-breeze/5.webp)

But before we can go on, we have to set up the database for this project, doing what we did in the first one. We go to the `.env` file and comment those lines:

```shell
# DB_CONNECTION=mysql
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=
```

and add

```shell
DB_CONNECTION=sqlite
```

to configure the SQLite database.

Now run

```shell
php artisan migrate
```

![Terminal output showing successful database migration with user tables created](https://flaviocopes.com/images/setting-up-authentication-using-laravel-breeze/6.webp)

In another terminal folder, run `npm install` followed by `npm run dev`, which is a long running process you’ll keep running alongside `php artisan serve` (⚠️ just make sure you’re running those in the `second` folder and not the `first` project, I just spent 15 minutes trying to figure out why I had a problem).

The Blade templates provided by Breeze use Tailwind CSS, and the setup of Tailwind was done automatically when we ran `php artisan breeze:install`

As you can see we already have a `tailwind.config.js` file.

Now you can open `resources/views/welcome.blade.php` and look at all that content. For the sake of simplicity, swap everything in that file with this trimmed-down version:

```shell
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    @vite('resources/css/app.css')
</head>

<body class="p-4">

    @if (Route::has('login'))
        <div class="text-right">
            @auth
                <a href="{{ url('/dashboard') }}" class="">Dashboard</a>
            @else
                <a href="{{ route('login') }}" class="">Log in</a>
                @if (Route::has('register'))
                    <a href="{{ route('register') }}" class="ml-4">Register</a>
                @endif
            @endauth
        </div>
    @endif

    <h1 class="pb-2 mb-3 font-bold border-b border-b-gray-300">
        Dogs
    </h1>

    <div>
        @auth
            <p>Logged in</p>
        @endauth

        @guest
            <p>Not logged in</p>
        @endguest
    </div>

</body>

</html>
```

`@auth` / `@endauth` and `@guest` / `@endguest` are two Blade directives that allow you to show content (or not) depending on the logged in state.

This should be the result in the browser:

![Simple Dogs webpage with Log in and Register links, showing Not logged in message](https://flaviocopes.com/images/setting-up-authentication-using-laravel-breeze/7.webp)

Click the Register link to create a new account:

![User registration page with form fields for creating a new account](https://flaviocopes.com/images/setting-up-authentication-using-laravel-breeze/8.webp)

Create an account and you will be shown a dashboard page at the `/dashboard` route:

![Laravel dashboard page with user profile navigation and welcome message after successful login](https://flaviocopes.com/images/setting-up-authentication-using-laravel-breeze/9.webp)

If you go back to the home, you will see the page in the logged in state:

![Dogs homepage showing Dashboard link instead of login options, displaying Logged in message](https://flaviocopes.com/images/setting-up-authentication-using-laravel-breeze/10.webp)
