我有一个控制器:
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
但是当我使用用户帐户登录时,它显示管理员页面。当我使用管理员帐户登录时,它显示访客页面,我不知道为什么,请帮忙!
答案 0 :(得分:0)
也许您的问题是之前不注销管理员帐户,您可以尝试使用此方法重新注册@guest
@if(!Auth::check() && !Auth()->guard('admins')->check())
//anything
@endif
祝你好运!