> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Email verification

> Learn the steps to implement Laravel's email verification feature. Covers model preparation, three route definitions, the verified middleware, customization, and events.

## Introduction

Email verification is a mechanism for confirming that a user actually owns the email address they registered with. Laravel provides sending and verifying confirmation emails out of the box, so you can build a secure authentication flow with minimal implementation.

<Info>
  If you use a starter kit, the authentication screens and email verification flow are already built in. If you implement it manually, follow the steps on this page to define the models, routes, and views yourself.
</Info>

## Preparing the model and database

### Implement MustVerifyEmail

Make sure `App\Models\User` implements `Illuminate\Contracts\Auth\MustVerifyEmail`.

```php theme={null}
<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;
}
```

Once you add this interface, a confirmation email is automatically sent to newly registered users. If you implement registration without a starter kit, fire the `Registered` event after successful registration.

```php theme={null}
use Illuminate\Auth\Events\Registered;

event(new Registered($user));
```

### Verify the email\_verified\_at column

You need an `email_verified_at` column on the `users` table. It is typically included in the default `0001_01_01_000000_create_users_table.php` migration.

## Routing (three routes)

Email verification defines three routes: `verification.notice`, `verification.verify`, and `verification.send`.

<Steps>
  <Step title="Define the verification notice route (verification.notice)">
    Returns a screen telling unverified users to "please check your email."

    ```php theme={null}
    Route::get('/email/verify', function () {
        return view('auth.verify-email');
    })->middleware('auth')->name('verification.notice');
    ```
  </Step>

  <Step title="Define the verification handler route (verification.verify)">
    When the user clicks the link in the email, this validates the signed URL and completes verification.

    ```php theme={null}
    use Illuminate\Foundation\Auth\EmailVerificationRequest;

    Route::get('/email/verify/{id}/{hash}', function (EmailVerificationRequest $request) {
        $request->fulfill();

        return redirect('/home');
    })->middleware(['auth', 'signed'])->name('verification.verify');
    ```
  </Step>

  <Step title="Define the resend route (verification.send)">
    Resends the confirmation email if the user loses it.

    ```php theme={null}
    use Illuminate\Http\Request;

    Route::post('/email/verification-notification', function (Request $request) {
        $request->user()->sendEmailVerificationNotification();

        return back()->with('message', 'Verification link sent!');
    })->middleware(['auth', 'throttle:6,1'])->name('verification.send');
    ```
  </Step>
</Steps>

## Protecting routes

To grant access only to verified users, use the `verified` middleware. It is typically combined with `auth`.

```php theme={null}
Route::get('/profile', function () {
    // Only verified users may access
})->middleware(['auth', 'verified']);
```

When an unverified user visits the route, Laravel automatically redirects them to `verification.notice`.

## Customization

To customize the verification email body, set `VerifyEmail::toMailUsing` in the `boot` method of your `AppServiceProvider`.

```php theme={null}
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Notifications\Messages\MailMessage;

public function boot(): void
{
    VerifyEmail::toMailUsing(function (object $notifiable, string $url) {
        return (new MailMessage)
            ->subject('Verify Email Address')
            ->line('Click the button below to verify your email address.')
            ->action('Verify Email Address', $url);
    });
}
```

## Events

The `Illuminate\Auth\Events\Verified` event is fired when email verification occurs. Starter kits handle this automatically, but for manual implementations, add event handling as needed.


## Related topics

- [Laravel Fortify and Starter Kits](/en/advanced/fortify.md)
- [Laravel Chisel — a post-install script library for starter kits](/en/blog/chisel-introduction.md)
- [Starter kits](/en/starter-kits.md)
- [Authentication introduction](/en/authentication.md)
- [CSRF protection](/en/csrf.md)
