authentication via Laravel using Breeze (r)

Jun 3, 2023
A computer monitor setup so someone can learn about laravel breeze

Then, send the information the information

This article will walk you through the features and functions of Laravel Breeze. It will also be compared with the various Laravel Start-up Kits as well as assist you with the process of installing it. Also, we'll look at the generated files, modify the registration process, and tweak your user experience (user interface) in order to satisfy the requirements of your particular application.

What's the purpose to Laravel Breeze?

The most important aspects of Laravel Breeze include:

  • Log in
  • Registration
  • Password reset
  • Verification of emails
  • Pages to edit your profile

Two applications that are similar to each other are offered inside the Laravel ecosystem. They could lead to confusion among those not acquainted to the Laravel ecosystem.

Think about Fortify when you have highly customized UI specifications or just accountable to backend authentication.

However, Laravel Breeze is best suited for developers looking for the most simple and adaptable authentication system capable of utilizing a variety of front-end frameworks, and also at low cost.

The launch to Laravel Breeze as A Fresh Laravel Project

The next step we'll be required to setup Laravel Breeze using the following instructions:

composer require laravel/breeze --dev

In this tutorial this guide, we'll use Blade which is the standard templating engine that is used by Laravel. To begin scaffolding, start with the following command:

php artisan breeze:install blade php artisan migrate npm install npm run dev

Laravel Breeze also has Vue React and Custom APIs. In order to use these APIs, all you have to do is put an option inside the command.

For Vue run:

artisan breeze PHP installation the view

For React run

React: Install PHP's art-blender

For custom API run

PHP Artisan breeze: install an API

What can I do? How can I customize the user interface? Interface

You can customize every part of the UI by editing the view files in the resources/views/auth; folder, some part of the UI is organized into Blade components, you can find these in the resources/views/components folder.

Laravel Breeze uses Blade components to arrange codes that are repeated. So, for example, here's how you can change the logo in the resources/views/components/application-blade.php file.

Changing the Color of the Primary Button
Change the color of the button's primary Button

Open the resources/views/components/primary-button.blade.php file. You are able to alter the icons displayed on your login page, based on the color scheme that is used in your logo.

Primary button changed to brand color
The color that was the primary hue that the button is modified to create completely new colorations

What do I need to change in order to change the flow of registration

The Laravel Breeze registration page comes with predefined 4 fields:

  1. Name
  2. Email
  3. Password
  4. Password confirmation
Registration page predefined fields
The fields that are predefined on the page of registration

To extend the fields we'd like our registration form to feature, we need to open the resources/views/auth/register.blade.php file.

To ensure that the scenario we've provided in the field for phone to go on, we'll place it after the email fields. For this to happen it's as simple as adding this code to the email field.

Telephone fields are evident in this registration form.

Phone field added
A phone field is in addition to

Modifying the Backend to preserve the Phone Field

We now have to manage the information that was moved into the database. This process involves three steps starting with the creation of and then implement the new model, which adds capabilities to the controller that houses the database information. Finally, you can incorporate telephones to the features that make up the model of users model.

Transfers can be made with a new phone field. It will go to our database of our users. table.

php artisan make:migration add_phone_field_to_users_table

The document can be accessed by creating a new field that has the word 'phone' as its title.

Schema::table('users', function (Blueprint $table) $table->string('phone')->nullable(); );

Once you have that done, you will be in a position to begin the process of migration

php artisan migrate

To store the phone field we need to modify the RegisteredUserController.php, in the store method make these modifications:

$request->validate([ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:'.User::class], 'phone' => ['required', 'string', 'max:255'], 'password' => ['required', 'confirmed', Rules\Password::defaults()], ]); $user = User::create([ 'name' => $request->name, 'email' => $request->email, 'phone' => $request->phone, 'password' => Hash::make($request->password), ]);

Be sure to include the telephone field in the fields of property that can be added to the model of the user.

protected $fillable = [ 'name', 'email', 'phone', 'password', ];

That's it! You can use new registration forms!

What do I need to do in order to enable Verification of Email? Verification

Email verification relies on confirm and verify email addresses that are provided by the user as part of their registration.

This function must be enabled in order to allow this feature, we need to create an interface called "MustVerifyEmail" Interface within the user model.

use Illuminate\Contracts\Auth\MustVerifyEmail; ... class User extends Authenticatable implements MustVerifyEmail ... 

An email following the confirmation has been sent when you have completed the registration when you click the link which is a confirmation of the email address.

But, we need to include a middleware in our network to stop access from users that aren't authenticated.

We'll design a new routing system named only-verified. We'll add "auth" along with "verified" middleware. Middleware that prevents access to authentication will be blocked to guests, while the verified middleware will verify if the user has been authenticated using their email.

The following is an illustration:

Route::get('/only-verified', function () return view('only-verified'); )->middleware(['auth', 'verified']);

Summary

Laravel Breeze is an ideal device to rapidly set the authentication process within your Laravel project.

With its easy-to-use and flexible design, you'll be able of focusing on the development of your app, without worrying about authentication.

The original article was posted on this website.

This article first appeared on here

The article was published on this website

Article was first seen on here