In this tutorials of Laravel, we will show you how to enable Laravel 8 Email Verification via Breeze package.
Steps
- Install Laravel 8
- Require Laravel Breeze Package
- Install Laravel Breeze Package
- Update User Model
- Update Web.php
- Migrate Database
Install Laravel 8
composer create-project laravel/laravel email-verification
Require Laravel Breeze Package
cd email-verification
composer require laravel/breeze --dev
Install Laravel Breeze Package
php artisan breeze:install
Update User Model
Path: app/Models/User.php, update class User extends Authenticatable to class User extends Authenticatable implements MustVerifyEmail. In below User Model we implemented MustVerifyEmail interface on User class.
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable implements MustVerifyEmail
{
use HasApiTokens, HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];
Update Web.php
Here in web.php file, we add ‘verified’ in middleware.
Route::get('/dashboard', function () {
return view('dashboard');
})->middleware(['auth','verified'])->name('dashboard');
Migrate Database
php artisan migrate