中间件中的handle
函数RedirectIfAuthenticated
总是返回守卫“admin”。
重定向IfAuthenticated
class RedirectIfAuthenticated
{
public function handle($request, Closure $next, $guard = null)
{
print_r($guard);
// if ($guard == "web" && Auth::guard($guard)->check()) {
// return redirect('/home');
// }
// if ($guard == "manager" && Auth::guard($guard)->check()) {
// return redirect('/manager');
// }
// if ($guard == "admin" && Auth::guard($guard)->check()) {
// return redirect('/admin');
// }
return $next($request);
}
}
配置/auth.php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'employees',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'employees',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
'manager' => [
'driver' => 'session',
'provider' => 'managers',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
],
'providers' => [
'employees' => [
'driver' => 'eloquent',
'model' => App\Employee::class,
],
'managers' => [
'driver' => 'eloquent',
'model' => App\Manager::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
'passwords' => [
'employees' => [
'provider' => 'employees',
'table' => 'password_resets',
'expire' => 60,
],
'managers' => [
'provider' => 'managers',
'table' => 'password_resets',
'expire' => 60,
],
'admins' => [
'provider' => 'admins',
'table' => 'password_resets',
'expire' => 60,
],
],
];