authentication with Laravel using Breeze (r)
Send the news to
The following article will go through the features of Laravel Breeze. We'll also compare it against the other Laravel start-up kits and then guide you through the process of installation. We'll also look at the created files, alter the registration procedure, and also tweak the user interface (user interface) to meet your particular application's requirements.
What does it mean by Laravel Breeze?
The most important aspects of Laravel Breeze are:
- Log in
- Registration
- Password reset
- Verification of emails
- Page for editing your profile
Two applications that are similar to one another are available within the Laravel ecosystem, which may create confusion for those who aren't familiar to the Laravel ecosystem.
It's worth considering Fortify if you're dealing with very custom UI requirements or if you're just accountable for backend authentication.
However, Laravel Breeze is best suited for developers looking for an incredibly simple, but versatile authentication system that can use a variety of front-end frameworks and at the lowest cost of operation.
The introduction of Laravel Breeze as A Fresh Laravel Project
In the next step, we'll have for installation of Laravel Breeze by following the instructions:
composer require laravel/breeze --dev
In this guide, we will use Blade which is the standard templating engine that is used by Laravel. For scaffolding to begin start by running these 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 access the APIs, all you need to do is include an option in the command.
For Vue run:
Artisan breeze PHP Install the view
For React run
React: Installation PHP's artisan breeze
For custom API run
php artisan breeze:install an API
How can I 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.
Change the Laravel Logo to Our Organization Logo
Laravel Breeze uses Blade components to arrange codes that are used several times. So, for example, here's how you can change the logo in the resources/views/components/application-blade.php
file.
Open the resources/views/components/primary-button.blade.php
file. It is possible to modify the buttons displayed on your login page depending on the color scheme of your branding.
What could I do to modify the registration Flow
The Laravel Breeze registration page comes with 4 predefined fields:
- Name
- Password
- Password confirmation
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 continue the examples we've provided for phone field, we'll place it after the email fields. For this to happen, simply add the following code following the email field.
Telephone fields are evident on the registration form.
Modifying the Backend to save the Phone Field
We now need to handle the data that has been transferred into the database. It is a three-step process to begin: develop, and then run an entirely brand new model that adds functions to the controller which stores the data. Then, finally, add telephones
to attributes in the model of the user
model.
You can make a transfer new that includes a telephone field to Our database of our users.
table.
php artisan make:migration add_phone_field_to_users_table
You can access to the file by adding a field with the name 'phone'
Schema::table('users', function (Blueprint $table) $table->string('phone')->nullable(); );
After that, you are in a position to carry out the 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 phone
field into those properties that you can complete on the model of the User.
protected $fillable = [ 'name', 'email', 'phone', 'password', ];
That's it! You can use the most current registration forms!
What can I do to turn on Email Verification
The process of email verification is based on the confirmation and verification of email addresses the user has supplied in their registration forms.
To enable this function, we have to integrate this feature, we must implement the "MustVerifyEmail"
Interface within the user model.
use Illuminate\Contracts\Auth\MustVerifyEmail; ... class User extends Authenticatable implements MustVerifyEmail ...
An email following the confirmation will be sent out after the person has signed up using the link which confirms their email.
But, we need to include a middleware in our networks in order to limit access to unauthenticated users.
We'll develop a new route called only-verified and add "auth" and "verified" middleware. Middleware that blocks auth access will be blocked to guests, while the verified middleware determines whether the user is authenticated through their email.
This is an example:
Route::get('/only-verified', function () return view('only-verified'); )->middleware(['auth', 'verified']);
Summary
Laravel Breeze is an excellent instrument for rapidly setting up the authentication process for you Laravel project.
Because of its user-friendly and scalable structure, you'll be capable of focusing on the development of your app, and not worry about the authentication.
The article was first published on this website
Article was first seen on here