-1

我有一个控制器:

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

但是当我使用用户帐户登录时,它会显示管理页面。当我使用管理员帐户登录时,它显示访客页面,我不知道为什么,请帮助!

4

1 回答 1

0

也许您的问题是之前不要注销管理员帐户,您可以尝试重新注册@guest

@if(!Auth::check() && !Auth()->guard('admins')->check())
//anything 
@endif

祝你好运!

于 2018-11-21T16:35:17.700 回答