DEV Community

Cover image for Email Verification After User Registration In Laravel
Salman Abbas (سلیمان)
Salman Abbas (سلیمان)

Posted on

Email Verification After User Registration In Laravel

How to verify user after registration?

In this blog post, we will learn how to implement email verification after user registration. We will implement this in three simple steps with the help of this post.

No matter if you have laravel/ui authentication or laravel/breeze authentication or any simple authentication you are using. In both authentication you just have to follow these steps.

Step #01: Create Or Open Laravel App:

  1. Go to the user model App\Model\User.php

  2. Implements MustVerifyEmail interface in User class

Include Destination

use Illuminate\Contracts\Auth\MustVerifyEmail;
Enter fullscreen mode Exit fullscreen mode

Implements Interface

class User extends Authenticatable implements MustVerifyEmail
Enter fullscreen mode Exit fullscreen mode

Step #02: Now let's assign middleware to the routes

Middleware you have to assign is the **verified middleware**

Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth','twofactor','verified'])>name('dashboard');
Enter fullscreen mode Exit fullscreen mode

Step # 03: Use Email Testing Tool

You can use mailtrap.io or any email testing tool.

1. First Create Your Inbox

Image description

  1. Now, let's go to the smtp settings and copy laravel details..

Image description

Now, paste these details in your .env file

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=1e8ad4d5513cbb
MAIL_PASSWORD=84a6b3c29196fc
MAIL_ENCRYPTION=tls
Enter fullscreen mode Exit fullscreen mode

Also you have add your email from which you have registered to the mailtrap.

MAIL_FROM_ADDRESS=youremail@email.com

Enter fullscreen mode Exit fullscreen mode

Now, Your application will have email verification service after user registration.

If you follow all steps

I hope this video will help you in implementing email verification in your laravel authentication.

Thanks!

Helpful video :
https://www.youtube.com/watch?v=C91xjfQZtxE

Top comments (0)