Auth:guard('partner')-> check()在身份验证中间件中给出false

时间:2019-06-22 15:29:36

标签: laravel authentication

嗨,我具有登录功能,在这里我成功进行了身份验证

PartnerLoginController.php

public function login(Request $request,AuthenticationException $exception)
{

    $this->validate($request, [
        'email'=>'required|email',
        'password'=>'required|min:6'

    ]);

    $credentials = ['email'=>$request->email,'password'=>$request->password];

    if(Auth::guard('partner')->attempt($credentials,$request->input('remember'))){
        dump(Auth::guard('partner')->check());//true
        return redirect()->intended(route('owner.dashboard'));
    }
    else{
        dd(Auth::guard('partner')->attempt($credentials,$request->input('remember')));
    }
    return redirect()->back()->withInput($request->only('email','remember'));
}

我成功收到了true,但是随后我重定向到了仪表板,并尝试在身份验证中间件中捕获$this->auth->guard('partner'),但是在这里我收到了false

Authenticate.php

protected function authenticate(array $guards)
{

    if (empty($guards)) {
        return $this->auth->authenticate();
    }
    foreach ($guards as $guard) {

        dump($guard);//partner
        dump($this->auth->guard($guard)->check());//false
        if ($this->auth->guard($guard)->check()) {
            return $this->auth->shouldUse($guard);
        }
    }

    dd('here2',$guards);//get here
    throw new AuthenticationException('Unauthenticated.', $guards);
}

为什么?似乎auth并没有保存在会话中。不像管理员登录过程

有我的身份验证设置文件

<?php

return [

    'defaults' => [
        'guard' => 'admin',
        'passwords' => 'admins',
    ],

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],
        'partner' => [
            'driver' => 'session',
            'provider' => 'partners',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],
        'admins' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],
        'superadmins' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],
        'partners' => [
            'driver' => 'eloquent',
            'model' => App\EstateOwners::class,
        ],

    ],

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],
        'admins' => [
            'provider' => 'admins',
            'table' => 'superadmin_password_resets',
            'expire' => 15,
        ],
        'superadmins' => [
            'provider' => 'superadmins',
            'table' => 'superadmin_password_resets',
            'expire' => 60,
        ],
        'partners' => [
            'provider' => 'partners',
            'table' => 'password_resets',
            'expire' => 15,
        ],
    ],

];

0 个答案:

没有答案