Setup
In order to use this feature, update your \App\Models\User::class
model to implement the HasEmailAddresses
interface
and use the HasEmailAddresses
trait like the following:
<?php
namespace App\Models;
//...
use YottaHQ\LaravelExtendedAuth\Contracts\HasEmailAddresses;
class User extends Authenticatable implements HasEmailAddresses
{
use \YottaHQ\LaravelExtendedAuth\Traits\HasEmailAddresses;
//...
}
Now you have linked the two models and can do for example:
$user->emailAddresses()->create([
'email' => request('email'),
]);
$emails = $user->emailAddresses;
Using the user provider for authentication
This package comes with a custom user provider https://github.com/yottahq/laravel-extended-auth/blob/main/src/Drivers/ExtendedUserProvider.php
which is similar
to Laravel's user provider but instead it's able to authenticate users with their secondary emails as well.
Update your config/auth.php
file and change your providers.users.driver
to laravelExtendedAuth
like in the example project:
'providers' => [
'users' => [
'driver' => 'laravelExtendedAuth',
'model' => App\Models\User::class,
],
// ...
]
Authenticating users with their secondary email addresses will only work if you set the authenticate_by_any_email
configuration
option to true
.