Laravel Breeze, a nimble package offered by the Laravel framework, simplifies the establishment of authentication scaffolding in your Laravel applications. This tutorial delves into the integration of Laravel Breeze with email verification, enhancing the security of user registration with an additional layer.
Prerequisites
Before getting started, make sure you have the following prerequisites:
- Laravel installed on your machine.
- Composer installed for managing Laravel dependencies.
- A database configured in your Laravel application.
Step 1: Install Laravel Breeze
Open your terminal and navigate to your Laravel project. Run the following command to install Laravel Breeze:
composer require laravel/breeze --dev
After the installation is complete, run the following command to set up Breeze:
php artisan breeze:install
This will create the necessary files and directories for authentication.
Step 2: Configure Email Verification
Laravel Breeze includes built-in support for email verification. To enable it, open the config/breeze.php
file and ensure that the features
array includes 'verify'
:
'features' => [
Features::registration(),
Features::resetPasswords(),
Features::emailVerification(),
Features::updateProfileInformation(),
Features::updatePasswords(),
Features::twoFactorAuthentication(),
],
Step 3: Run Migrations
Run the migration command to create the necessary tables in your database:
php artisan migrate
This will create tables for users, password resets, and email verifications.
Step 4: Set Up Mail Configuration
Laravel uses mail to send verification emails. Make sure your .env
file is configured with the proper mail settings, such as MAIL_MAILER
, MAIL_HOST
, MAIL_PORT
, etc.
MAIL_MAILER=smtp
MAIL_HOST=your-mail-host
MAIL_PORT=your-mail-port
MAIL_USERNAME=your-mail-username
MAIL_PASSWORD=your-mail-password
MAIL_ENCRYPTION=your-mail-encryption
Step 5: Customize Views (Optional)
You can customize the email verification views by publishing them:
php artisan vendor:publish --tag=breeze-views
This command will copy the views to the resources/views/vendor/breeze/auth
directory, allowing you to modify them according to your application’s design.
Step 6: Update Routes
Open the routes/web.php
file and ensure that the auth
routes include the verified
middleware:
Route::middleware(['auth', 'verified'])->group(function () {
// Your authenticated routes here
});
This middleware ensures that only verified users can access the specified routes.
Step 7: Test the Setup
Run your Laravel development server:
php artisan serve
Go to your application through the browser, sign up as a new user, and look in your email for the verification link. Click on the link to confirm your email address.
Well done! You’ve now configured Laravel Breeze with email verification, adding an extra layer of security to ensure that only legitimate and verified users can use your application.
Feel at liberty to discover additional features offered by Laravel Breeze and tailor your authentication process to suit your application’s needs.
Check our tools website Word count
Check our tools website check More tutorial