@guest 判断是否为游客
//在登录时会使用
<ul class="navbar-nav navbar-right">
<!-- Authentication Links 游客,blade的判断方法guest-->
@guest
<li class="nav-item"><a class="nav-link" href="{{ route('login') }}">登录</a></li>
<li class="nav-item"><a class="nav-link" href="{{ route('register') }}">注册</a></li>
@else
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img src="https://cdn.learnku.com/uploads/images/201709/20/1/PtDKbASVcz.png?imageView2/1/w/60/h/60" class="img-responsive img-circle" width="30px" height="30px">
{{ Auth::user()->name }}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" id="logout" href="#"
onclick="event.preventDefault();document.getElementById('logout-form').submit();">退出登录</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</div>
</li>
@endguest
</ul>
退出登录的a链接
<a class="dropdown-item" id="logout" href="#"
onclick="event.preventDefault();document.getElementById('logout-form').submit();">退出登录</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
网友评论