handle()函数在RedirectIfAuthenticated中间件中返回防护“ admin”

时间:2019-09-06 11:46:56

标签: php laravel laravel-6

handle中间件中的RedirectIfAuthenticated函数始终返回防护“ admin”。

RedirectIfAuthenticated

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);
    }
}

config / 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,
        ],

    ],

];

0 个答案:

没有答案