DEV Community

Arman Rahman
Arman Rahman

Posted on

How To Enable Email Verification On Laravel

Email verification is the process of checking and authenticating emails that users have been provided in the registration form.

To enable this feature we need to implement MustVerifyEmailinterface in our User model.

use Illuminate\Contracts\Auth\MustVerifyEmail;
…

class User extends Authenticatable implements MustVerifyEmail
{
…
}
Enter fullscreen mode Exit fullscreen mode

After that, an email will be sent out when a user registers with a link to verify their email.

However, we still need to add a middleware to our routes where we want to restrict access to unverified users.

We will create a new route called ‘only-verified’ and we will add ‘auth’ and ‘verified’ middleware. The auth middleware prevents access to guests and the verified middleware checks whether the user has verified their email.

Here is an example:

Route::get('/only-verified', function () {
   return view('only-verified');
})->middleware(['auth', 'verified']);

Enter fullscreen mode Exit fullscreen mode

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more