Using Laravel Fortify to restore laravel/ui functionality
Tags: laravel, authentication, auth, fortify
Published: 2020-09-17 01:38:29

---
title: Using Laravel Fortify to restore laravel/ui functionality
published: true
description: Step by step on how to setup basic authentication using Laravel Fortify 
tags: laravel, authentication, auth, fortify
cover_image: https://i.imgur.com/x8IMrry.png
---
Since the release of Laravel 8 and Jetstream, the package `laravel/ui` fall in some kind of deprecated status.

The problem with Jetstream (and i think many of us feel the same) is that we just want the auth scaffolding without the need of Inertia.js or Livewire stacks.

Don't get me wrong, i love working with Inertia or Livewire, but sometimes you just need the auth part.

Going back to `laravel/ui`, it's still possible to use the package on Laravel 8, but i wanna restore that functionality without mentioned package.

In the  guide i'm gonna describe all my steps to have a similar behavior using Laravel Fortify.


## Project setup
1. `laravel new laravel-fortify-demo`
2. `composer require laravel/fortify`
3. `php artisan vendor:publish --provider="Laravel\\Fortify\\FortifyServiceProvider"`
4. configure your database
5. `php artisan migrate`

## Setup Fortify
Open `config/app.php` and register Fortify service provider:
```php
App\Providers\FortifyServiceProvider::class,
```

Next, open `config/fortify.php` and update your features array as follow:
```php
'features' => [
    Features::registration(),
    Features::resetPasswords(),
],
```

Now we need to tell Fortify where is our auth views.

Open `app/Providers/FortifyServiceProvider.php` and in the `boot` method add:

```php
Fortify::loginView(function () {
    return view('auth.login');
});

Fortify::registerView(function () {
    return view('auth.register');
});

Fortify::requestPasswordResetLinkView(function () {
    return view('auth.forgot-password');
});

Fortify::resetPasswordView(function () {
    return view('auth.reset-password');
});
```

## Create the views
We need to create the 4 mentioned blade files:
* resources/views/auth/forgot-password.blade.php
* resources/views/auth/login.blade.php
* resources/views/auth/register.blade.php
* resources/views/auth/reset-password.blade.php

I "borrowed" the views from the `laravel/ui` package; you can grab [here](https://github.com/skydiver/laravel-fortify-demo/tree/master/resources/views/auth)

## Protect your pages
Now we need to protect our routes, open `routes/web.php` and use `auth` middleware, like:
```php
Route::get('/', function () {
    return view('welcome');
})->middleware(['auth']);
```

## Final words
As you can see, this article covers the basic register, login and password reset functionalities.

Fortify includes an interesting email verify feature; if you're interested you can take a look on the package [documentation](https://github.com/laravel/fortify#email-verification)

Keep in mind that the auth views (including the bundled css and js files) are made for demo purposes only; you will need to take care of the ui.

## GitHub repository
If you wanna take a look for the final version, feel free to visit [skydiver/laravel-fortify-demo](https://github.com/skydiver/laravel-fortify-demo) repo.