Auth::guard() 在视图 laravel 5.7 中工作错误
Auth::guard() is working wrong in view laravel 5.7
我有一个控制器:
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
但是当我使用用户帐户登录时,它显示管理页面。当我用管理员帐户登录时,它显示访客页面,我不知道为什么,请帮助!
可能你的问题是之前没有登出admins账号,你可以试试这个重新装盘@guest
@if(!Auth::check() && !Auth()->guard('admins')->check())
//anything
@endif
祝你好运!
我有一个控制器:
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
但是当我使用用户帐户登录时,它显示管理页面。当我用管理员帐户登录时,它显示访客页面,我不知道为什么,请帮助!
可能你的问题是之前没有登出admins账号,你可以试试这个重新装盘@guest
@if(!Auth::check() && !Auth()->guard('admins')->check())
//anything
@endif
祝你好运!