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 guide you through all the features and capabilities of Laravel Breeze. It'll also compare it to the different Start-up Kits for Laravel as well as assist you with the installation process. We'll also look over the files generated, alter the registration procedure as well as alter your user experience (user interface) in order to meet the specifications of your specific application.

What's the reason behind Laravel Breeze?

The most significant aspects of Laravel Breeze include:

  • Log in
  • Registration
  • Password reset
  • Verification of emails
  • Pages that you can edit on your profile

Two applications that are similar to one another are available in the Laravel ecosystem. They could lead to confusion for those who are not familiar with the Laravel ecosystem.

You should think about Fortify for when you're using very specific UI requirements or are you are accountable for backend authentication.

However, Laravel Breeze is best designed for those who are looking for an easy and flexible authentication system capable of utilizing different front-end frameworks, and also for those who want to save money.

The launch to Laravel Breeze as A Fresh Laravel Project

In the next stage, will be to install Laravel Breeze with the following steps:

composer require laravel/breeze --dev

In this instructional guide will use Blade that is the standard templating engine utilized by Laravel. To begin scaffolding, start by using the following instruction:

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

Laravel Breeze also has Vue React and Custom APIs. To use the APIs you need to do is put an option in the command.

For Vue run:

artisan breeze PHP installation the look

For React run

React: Install PHP's art-blender

For custom API run

PHP Artisan breeze: Install an API

What can I do? What can I do to customize the user interface? 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 organize codes which 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 primary button

Open the resources/views/components/primary-button.blade.php file. You are able to alter the icon icons that appear on the login page in accordance with the color scheme employed in your logo.

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

What do I need to modify in order to alter the process 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 which are defined on the registration page

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

In order to ensure that the situation that we've created in the phone field is able will be followed, we'll place it after that email field. In order to do this, it's just as easy as adding the code to the email field.

Telephone fields are obvious on this registration form.

Phone field added
A telephone field is in combination with

Modifying the Backend to keep the Phone Field

We now have to manage the data that has been moved into the database. This is a process that involves three steps, beginning with development of the new model. This gives capabilities to the controller which houses the information in the database. Additionally, you could add telephones in the attributes that make up the user model model.

Transfers are possible using a new phone field. It will go to our database of our customers. table.

php artisan make:migration add_phone_field_to_users_table

The document is accessed by creating a new field with the word "phone" in its name.

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

When you've done that, you will be ready to start 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 phone field in the fields of property that can be added to an existing model that represents the users.

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

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

What should I do to allow Verification of Email? Verification

Email verification is based on the confirmation and confirm email addresses that users provide as part of their registration.

This function must be enabled in order to allow this function, and we have to design an interface called "MustVerifyEmail" Interface within the user model.

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

A confirmation email is sent once you've successfully completed the registration after you click on the link which is an email confirmation address.

But, we need to incorporate a middleware into our network to stop access for users who do not have a valid identity.

We'll develop a unique routing system called only-verified. We'll include "auth" as well as "verified" middleware. Middleware that blocks access to authentication is blocked to guests, while the verified middleware will confirm whether the user is authenticated with their email.

This is an example:

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

Summary

Laravel Breeze is the ideal tool to quickly set up the process of authentication in the Laravel project.

Thanks to its user-friendly and adaptable layout, you'll be capable to focus on the design of your app, without stressing about security.

The original article was posted on this site.

This article first appeared on this site

The article was posted on this website

This article first appeared on this site

Article was posted on here