DEV Community

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

Posted on

3 1

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

Give your career some juice. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay