Yes! It's possible. And to do that you will have to rewrite the sendEmailVerificationNotification
in your App\User
. This method is provided by the Illuminate\Auth\MustVerfiyEmail
trait. The method sendEmailVerificationNotification
notifies the created user
by sending an Email as defined in the Illuminate\Auth\Notifications\VerifyEmail
Notification class.
// This is the code defined in the sendEmailVerificationNotification
public function sendEmailVerificationNotification()
{
$this->notify(new Notifications\VerifyEmail);
}
You can change this method to not notify directly the user. You will have to define a Job
which you will dispath in the sendEmailVerificationNotification
method instead of notifying the created user.
In the Job
class you will create a handle
method where you can send the email to the user
, but you must provide the $user
to the Job which can be performed by passing it as a parameter to the dispatch
method like this:
public function sendEmailVerificationNotification()
{
VerifyEmail::dispatch($this);
}
$this
represents the created user
and the App\Jobs\VerififyEmail
job (which you will create) will receive all the parameters passed to the dispatch
in its __construct
The code of the VerifyEmail
will look like this:
namespace App\Jobs;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Auth\Notifications\VerifyEmail;
class VerifyEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function handle()
{
// Here the email verification will be sent to the user
$this->user->notify(new VerifyEmail);
}
}