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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

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

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay