DEV Community

Cover image for Using Laravel Fortify to restore laravel/ui functionality
Martin M.
Martin M.

Posted on

Using Laravel Fortify to restore laravel/ui functionality

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:

App\Providers\FortifyServiceProvider::class,

Next, open config/fortify.php and update your features array as follow:

'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:

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

Protect your pages

Now we need to protect our routes, open routes/web.php and use auth middleware, like:

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

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 repo.

Top comments (1)

Collapse
 
tomstreeter profile image
Tom Streeter

You may have just saved my butt.