Laravel Authentication Using Breeze
This post will explore Laravel Breeze’s features, evaluate it against other Laravel starter kits, and guide you through the installation procedure.
Laravel Breeze
Laravel Breeze is a scaffolding package for authentication designed for Laravel. With its help, you may quickly establish a login and registration system that functions flawlessly. It has an API version that supports Blade, Vue, and React.
The main features of Laravel Breeze are:
- Login
- Registration
- Password reset
- Email verification
- Profile page, with editing
Installing Laravel Breeze to a Fresh Laravel Project
To keep it easy I assume that you already have a new Laravel Project ready to implement authentication using Breeze.
After that, we need to install Laravel Breeze with the following command:
composer require laravel/breeze --devph
e will use Blade which is the default templating engine for Laravel. To start the scaffolding run these commands:
php artisan breeze:install blade
php artisan migrate
npm install
npm run dev
Laravel Breeze also has Vue / React / custom API versions, to use them you just need to put a flag in the command.
For Vue/react/api run any one of these:
php artisan breeze:install vue/react/api
You’ll discover that multiple files have been generated in your project directory after installing Laravel Breeze. The files that manage email verification, password resets, and authentication are called routes, controllers, and views. You can examine these files and alter them to meet the needs of your application.
Customize the UI using Breeze
By default Breeze uses Tailwind CSS under the hood, to customize the UI we can use any Tailwind utility class.
You can customize every part of the UI by editing the view files in the resources/views/auth
;
some part of the UI is organized into Blade components, you can find these in the resources/views/components
folder.
You can customize the Registration page given by this package which can be found easily on this path resources/views/auth/register.blade.php
file You can add or remove any input tags for details for the registration.
if you have made any changes in the form then you need to customize it in the backend also and after that, you need to run the migration using command php artisan migrate after migration of files you need to update it in RegisteredUserController.php which can be found in auth folder.
Enable Email Verification
Email verification is the process of checking and authenticating emails that users have been provided in the registration form.
To enable this feature we need to implement MustVerifyEmail
interface in our User model.
use Illuminate\Contracts\Auth\MustVerifyEmail;
…
class User extends Authenticatable implements MustVerifyEmail
{
…
}
After that, an email will be sent out when a user registers with a link to verify their email.
However, we still need to add a middleware to our routes where we want to restrict access to unverified users.
We will create a new route called ‘only-verified’ and we will add ‘auth’ and ‘verified’ middleware. The auth middleware prevents access to guests and the verified middleware checks whether the user has verified their email.
Here is an example:
Route::get('/only-verified', function () {
return view('only-verified');
})->middleware(['auth', 'verified']);
Conclusion
A fantastic tool for quickly configuring an authentication system for your Laravel project is Laravel Breeze.
Its straightforward yet adaptable framework allows you to concentrate on developing your app rather than worrying about the authentication procedure.
Check out our Laravel hosting option if you’re searching for a location to host your new Laravel application. It has a ton of features that make managing and deploying apps fast and simple.