Email Verification

Many web applications require users to verify their email addresses before using the application. Rather than forcing you to re-implement this on each application, Laravel provides convenient methods for sending and verifying email verification requests.

To get started, verify that your model implements the Illuminate\Contracts\Auth\MustVerifyEmail contract:

Database Considerations

The Email Verification Column

Next, your user table must contain an email_verified_at column to store the date and time that the email address was verified. By default, the users table migration included with the Laravel framework already includes this column. So, all you need to do is run your database migrations:

  1. php artisan migrate

Laravel includes the Auth\VerificationController class that contains the necessary logic to send verification links and verify emails. To register the necessary routes for this controller, pass the option to the Auth::routes method:

Protecting Routes

can be used to only allow verified users to access a given route. Laravel ships with a verified middleware, which is defined at Illuminate\Auth\Middleware\EnsureEmailIsVerified. Since this middleware is already registered in your application's HTTP kernel, all you need to do is attach the middleware to a route definition:

  1. Route::get('profile', function () {
  2. // Only verified users may enter...
  3. })->middleware('verified');

Views

The email verification view is placed in resources/views/auth/verify.blade.php. You are free to customize this view as needed for your application.

After an email address is verified, the user will automatically be redirected to /home. You can customize the post verification redirect location by defining a redirectTo method or property on the VerificationController:

    Events