我有一个控制器:
if( Auth::attempt(['mssv' => $username,'password' =>$password])) {
$success = new MessageBag(['successlogin' => 'Login Success]);
return redirect()->back()->withErrors($success);
}
elseif( Auth::guard('admins')->attempt(['manv' => $username,'password' =>$password])) {
$success = new MessageBag(['successlogin' => 'Login Success]);
return redirect()->back()->withErrors($success);
}
else {
$errors = new MessageBag(['errorlogin' => 'Login Fail']);
return redirect()->back()->withErrors($errors);
}
并查看:
@guest
<li class="nav-item">
<a class="nav-link" href="#">Guest page</a>
</li>
@endguest
@auth
@if(Auth()->guard('admins')->check())
<li class="nav-item">
<a class="nav-link" href="#">Admin Page</a>
</li>
@elseif(Auth()->user()->check())
<li class="nav-item">
<a class="nav-link" href="#">User Page</a>
</li>
@endif
@endauth
但是当我使用用户帐户登录时,它会显示管理页面。当我使用管理员帐户登录时,它显示访客页面,我不知道为什么,请帮助!