我有三个用户(Staff,Admin,Hr)...使用不同的防护措施进行限制。其他防护措施工作正常,但默认为Web防护措施,而职员(用户)的防护措施则不允许我登录它有任何错误吗?
这是我的登录功能
public function logged(Request $request)
{
$this->validate($request,[
'email' => 'required|email',
'password' => 'required|min:6'
]);
if (Auth::guard('web')->attempt(['email'=>$request->email,
'password' => $request->password]))
{
return redirect()->intended(url('/home'));
}
Session::flash('message','Invalid Login details');
return redirect()->back()->withInput($request->only('email','remember'));
}
Below is my middleware
public function handle($request, Closure $next, $guard = null)
{
switch($guard){
case 'admin':
if(Auth::guard($guard)->check()){
return redirect()->route('admin.dashboard');
}
break;
case 'hr':
if(Auth::guard($guard)->check()){
return redirect()->route('hr.dashboard');
}
break;
default:
if(Auth::guard($guard)->check()){
return redirect()->route('home');
}
return $next($request);
}
**以下是我要求的config / auth.php **
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'admin'=> [
'driver' => 'session',
'provider' => 'admins',
],
'admin-api' => [
'driver' => 'token',
'provider' => 'admins',
],
'hr' => [
'driver' => 'session',
'provider' => 'hrs',
],
'hr-api' =>[
'driver' => 'token',
'provider' => 'hrs'
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Models\Admins::class,
],
'hrs' => [
'driver' => 'eloquent',
'model' => App\Hr::class,
],
'users' => [
'driver' => 'database',
'table' => 'users',
],
],
答案 0 :(得分:0)
如果您跳过防护措施而只使用默认值,会发生什么情况,因此对于default:
,请执行以下操作
if (Auth::check()) {
return redirect()->route('home');
}