Laravel Fortify: Implement Authentication Scaffolding In Laravel 8

Razet · · 9333 Views

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

  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:

  1. resources/views/auth/forgot-password.blade.php

  2. resources/views/auth/login.blade.php

  3. resources/views/auth/register.blade.php

  4. 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, 

  1. Forget Password & User Profile Update

  2. Email verification tutorial video tutorial

  3. Two Factor Authentication (2FA)

0

Please login or create new account to add your comment.

0 comments
You may also like:

Building a Real-Time Chat App with Laravel Reverb and Nuxt 3

Building a real-time chat application is a great way to understand the power of WebSockets and real-time communication. In this tutorial, we will walk through creating a Real-Time (...)
Harish Kumar

How to Set Up Nuxt 3 Authentication with Laravel Sanctum (Step-by-Step Guide)

In modern web development, securing your application’s authentication process is a top priority. For developers building Single Page Applications (SPA) or Server-Side Rendered (...)
Harish Kumar

Laracon US 2024: Laravel 11 Minor Features That Enhance Performance

At Laracon US 2024, Taylor Otwell and the Laravel team introduced a series of "minor" features for Laravel 11 that are anything but minor. These enhancements, while not headline-grabbing (...)
Harish Kumar

PHP OPCache: The Secret Weapon for Laravel Performance Boost

OPCache, a built-in PHP opcode cache, is a powerful tool for significantly improving Laravel application speed. This guide will demonstrate how to effectively utilize OPCache to (...)
Harish Kumar

How to Use DTOs for Cleaner Code in Laravel, Best Practices and Implementation Guide

When developing APIs in Laravel, ensuring your responses are clear, concise, and consistent is crucial for creating a maintainable and scalable application. One effective way to (...)
Harish Kumar

Data Type Validation in Laravel Collections with the `ensure()` Method

Before moving on to the ensure() method, let us first know what Laravel Collections actually are. These are wrappers of PHP arrays, offering a fluent and helpful interface in interacting (...)
Harish Kumar