如果我理解正確的話,用戶必須驗證其自身然後你想檢查角色。不需要具有特定的角色。在文件的頂部
/**
* The user has been authenticated.
*
* @param \Illuminate\Http\Request $request
* @param mixed $user
* @return mixed
*/
protected function authenticated(Request $request, $user)
{
if(empty($user->role)) {
$this->guard()->logout();
return back()->withErrors(['There is no role specified']);
}
}
如果你希望用戶;(你必須寫使用照亮\ HTTP \請求:如果是這樣,你可以在你的LoginController這樣覆蓋認證()方法。有特定的角色,你可以重寫LoginController中的credentials()方法:
protected function credentials(Request $request)
{
$credentials = $request->only($this->username(), 'password');
$credentials['role'] = 'requiredRole';
return $credentials;
}
非常感謝這是我正在尋找的! – fefe