0
votes

I'm using the Laravel Notifiable trait on my user model so users have to verify their e-mail address before being able to login, this works fine.

However, I want to delay the sending of this e-mail until a later point in the application (when the admin manually confirms each user).

How do I prevent Laravel from sending the verify e-mail on account creation?

When creating a user manually you can use the SendsPasswordResetEmails trait to send the verification email whenever you like in your application:

use SendsPasswordResetEmails;
$this->sendResetLinkEmail($request);

The problem is I can't find this code in the standard Laravel authentication scaffolding to prevent it from happening.

2

2 Answers

1
votes

The Notifiable trait is not what is sending the email verification to the user, but the MustVerifyEmail interface that your User model implements.

So in order to do it manually what you need to do is remove this lines from the

EventServiceProvider $listen mappings:

Registered::class => [
    SendEmailVerificationNotification::class,
]

and then at later point you can find the User to which you want to send the email verification and send the email like this:

User::find($userId)->sendEmailVerificationNotification();
0
votes

As @nakov mentioned, it is the MustVerifyEmail interface that Laravel uses to perform its magic. Laravel checks if the class to be notified (i.e. User) implements the MustVerifyEmail interface, and if so, sends out the verification notification.

While you could remove the Registered event listener from your EventServiceProvider, you can also just remove implements MustVerifyEmail from your User class.

By keeping the event listener in tact and simply removing the MustVerifyEmail interface from your User class, you keep the automated email verification system in tact in case you do want to create another type of User class does get automated email verification notifications.

So, remove implements MustVerifyEmail from your User class, and then manually call sendEmailVerificationNotification() on your user whenever you want to send out the verification email.