我使用自定义视图实现了 Fortify Multi Auth Guard(管理员和用户)。我有管理员和用户的单独登录视图。我还为用户实施了忘记密码,并且运行良好。我只是无法为管理员实施忘记密码。此外,我还想为管理员和用户实施电子邮件验证。我找到了一半的解决方案请允许我解释一下:-
供应商/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));
}
如果我将上述方法修改如下,它仅适用于用户
public function broker($name = null)
{
$name = $name ?: $this->getDefaultDriver();
return $this->brokers[$name[0]] ?? ($this->brokers[$name[0]] = $this->resolve($name[0]));
}
如果我如下修改方法,它仅适用于管理员
public function broker($name = null)
{
$name = $name ?: $this->getDefaultDriver();
return $this->brokers[$name[1]] ?? ($this->brokers[$name[1]] = $this->resolve($name[1]));
}
根据要求,它将如何为两者工作?覆盖提到的 broker() 方法的最佳方法是什么?
配置/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,
];
配置/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,
]),
],
];