DEV Community

Cover image for Queuing Laravel email verification

Posted on

Queuing Laravel email verification

When building a Laravel application, one may want the user to verify their email address to avoid fake users. Generally, this email verification process is done behind the scenes just after the user has registered on your application. After we store the user information in the database, we dispatch an event that automatically sends the verification mail to that user. However, the registration and verification process can sometimes delay the following code execution. For example, we could want to respond quickly to the user to signify that his registration passed. What we could do to speed up our users' registration is to queue our email verification.
To achieve that, we should:

Note: I suggest referring to the Laravel documentation if you're unfamiliar with queuing tasks.

First, create a new notification that extends the Laravel Illuminate\Auth\Notifications\VerifyEmail notification class.

Our SendVerificationEmail notification class

Ensure that your SendVerificationEmail notification class implements the ShouldQueue interface as shown in the figure.

Then in your App\Models\User class, override the sendEmailVerificationNotification method to make it send SendVerificationEmail notification instead of Illuminate\Auth\Notifications\VerifyEmail.

Overriding the sendEmailVerificationNotification method

When a user registers and the Illuminate\Auth\Events\Registered event is dispatched, the verification email-sending process runs in the background and let the following code execute without being interrupted.


This article is only about queuing email verification. We could not go deep because it is a tip that I quickly wanted to share with you. I hope you have found it helpful.

Top comments (0)