I implemented Fortify Multi Auth Guard (Admin and User) with Custom view. I have separate login view for admin and user. I have also implemented Forgot Password for user and it is working very well. I am just unable to implement Forgot Password for Admin. Further I also want to implement email verification for both Admin and User. I have found half solution Please allow me to explain:-
vendor/laravel/framework/src/illuminate/Auth/Passwords/PasswordBrokerManager.php
public function broker($name = null)
{
$name = $name ?: $this->getDefaultDriver();
return $this->brokers[$name] ?? ($this->brokers[$name] = $this->resolve($name));
}
If i modify the above method as below it works for user only
public function broker($name = null)
{
$name = $name ?: $this->getDefaultDriver();
return $this->brokers[$name[0]] ?? ($this->brokers[$name[0]] = $this->resolve($name[0]));
}
And If i modify the method as below it works for admin only
public function broker($name = null)
{
$name = $name ?: $this->getDefaultDriver();
return $this->brokers[$name[1]] ?? ($this->brokers[$name[1]] = $this->resolve($name[1]));
}
How will it work for both as per requirement ? What is the best way to override mentioned broker() method ?
config/auth.php
<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Models\Admin::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'admins' => [
'provider' => 'admins',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
'password_timeout' => 10800,
];
config/fortify.php
<?php
use App\Providers\RouteServiceProvider;
use Laravel\Fortify\Features;
return [
'guard' => 'web',
'passwords' => ['users', 'admins'],
'username' => 'email',
'email' => 'email',
'home' => RouteServiceProvider::HOME,
'prefix' => '',
'domain' => null,
'middleware' => ['web'],
'limiters' => [
'login' => 'login',
'two-factor' => 'two-factor',
],
'views' => true,
'features' => [
Features::registration(),
Features::resetPasswords(),
// Features::emailVerification(),
Features::updateProfileInformation(),
Features::updatePasswords(),
Features::twoFactorAuthentication([
'confirmPassword' => true,
]),
],
];