Multiple Email Addresses
Email Verification

Email Verification

Email verification for email addresses is provided out of the box using the package.

The package has its own Event Service Provider that listens to the \YottaHQ\LaravelExtendedAuth\Events\UserEmailAddressAdded event which should be fired on adding a new email address.

On the other hand, there's the \YottaHQ\LaravelExtendedAuth\Listeners\SendEmailVerificationNotification listener that handles sending verification email.

Sending the verification email

All you need to do is to fire the UserEmailAddressAdded event on adding any new email address and the listener will take care of the rest:

$user = auth()->user();
 
$email = $user->emailAddresses()->create([
    'email' => 'test@email.com',
]);
 
event(new \YottaHQ\LaravelExtendedAuth\Events\UserEmailAddressAdded($email));

If you want to handle the sending of verification email on your own, just execute the sendEmailVerificationNotification() function on any UserEmailAddress entity, and it will send the notification:

// ...
 
$email = $user->emailAddresses()->create([
    'email' => 'test@email.com',
]);
 
$email->sendEmailVerificationNotification();

But don't forget that in this case you will need to customise the verification url sing the following code (This is done by default in the listener):

https://github.com/yottahq/laravel-extended-auth/blob/main/src/Listeners/SendEmailVerificationNotification.php#L17
VerifyEmail::createUrlUsing(function ($notifiable) {
    return URL::temporarySignedRoute('verification.verify-user-email',
        Carbon::now()->addMinutes(Config::get('laravel-extended-auth.email_verification_link_expiry', 60)),
        [
            'id' => $notifiable->getKey(),
            'hash' => sha1($notifiable->getEmailForVerification()),
        ]
    );
});
Last updated on December 25, 2022