Laravel Fortify: Implement Authentication Scaffolding In Laravel 8
Since the arrival of Laravel 8 and Jetstream, the package laravel/ui
fall in some sort of deprecated status.
The issue with Jetstream is that we simply need the auth scaffolding without the need of Inertia.js or Livewire stacks.
Don't get me wrong, I love working with Inertia or Livewire, yet in some cases, you only need the auth part.
Going back to laravel/ui
, it's as yet conceivable to utilize the package on Laravel 8. However, I want to restore that functionality without the referenced package.
In the guide, I'm going to describe steps to have similar behavior using Laravel Fortify.
Project setup
laravel new laravel-fortify-demo
composer require laravel/fortify
php artisan vendor:publish --provider="Laravel\\Fortify\\FortifyServiceProvider"
configure your database
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;
Conclusions
This article covers the essential register, login, and password reset functionalities.
Here are some other features of Laravel fortify,
Please login or create new account to add your comment.