authentication through Laravel using Breeze (r)

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

Then, send the information to

This article will walk you through the functions of Laravel Breeze. It will also be compared to the other Laravel Start-up Kits and help you with the process of installing it. We'll also look at the generated files, change the registration procedure and also tweak your user experience (user interface) in order to satisfy your specific application's requirements.

What is the meaning behind Laravel Breeze?

The most significant aspects of Laravel Breeze include:

  • Log in
  • Registration
  • Password reset
  • Verification of emails
  • Pages for editing your profile

Two programs that are comparable to one another are available in the Laravel ecosystem. These applications could create confusion for people who aren't acquainted with the Laravel ecosystem.

Consider Fortify in the case of highly customized UI specifications or just accountable for backend authentication.

But, Laravel Breeze is best suited for developers looking for an incredibly simple, but flexible authentication system that is able to utilize a range of front-end frameworks and at low cost.

The introduction of Laravel Breeze as A Fresh Laravel Project

The next step we'll be required to set up 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. For scaffolding to begin start by running the following commands:

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

Laravel Breeze also has Vue React as well as Custom APIs. To use the 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: Installation PHP's art-blender

For custom API run

PHP artisan breeze: install an API

What can I do to customize the User 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 that appear on your login page based on the color scheme of your logo.

Primary button changed to brand color
The primary color of the button was altered to produce entirely new colors

What can I do to alter the registration flow

The Laravel Breeze registration page comes with 4 predefined 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 keep the example that we've given for the phone field to continue, we'll put it in after that of the fields in email. For this to happen it is as easy as adding this code to that email field.

Telephone fields are evident in the registration form.

Phone field added
A phone field is as an additional

Modifying the Backend to save the Phone Field

Now we must manage the information that was moved into the database. The process is three steps beginning with the development of and then implement a completely new model which adds capabilities to the controller which houses the information. Finally, you can add telephones to the attributes of the model of the user model.

You can make a transfer new that includes a telephone field. It will go to our database of our users. table.

php artisan make:migration add_phone_field_to_users_table

Access to the document by adding a field with the title 'phone'

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), ]);

Make sure to add the telephone field into the property fields that you could add to the model of the user.

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

That's it! It is possible to use the latest registration forms!

What can I do to enable Email Verification

The process of email verification is dependent on confirmation and verification of email addresses provided by the user in their form of registration.

To enable this function in order to enable this function, and we must implement an interface called "MustVerifyEmail" Interface within the model of user.

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

An email following the confirmation is sent once the sign-up has been completed by clicking the link that confirms the email address.

But, we need to add a middleware to our networks in order to prevent access for users that aren't authenticated.

We'll design a new routing system called only-verified and add "auth" as well as "verified" middleware. Middleware that prevents access to auth will be blocked to guests, while the verified middleware will determine if the user is authenticated through their email.

The following is an example:

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

Summary

Laravel Breeze is an ideal tool for quickly setting up your authentication procedure in your Laravel project.

Because of its user-friendly and flexible architecture, you'll be able of focusing on the development of your app, without worrying about authenticating.

The original article was published on this website

This article first appeared on here

Article was posted on here