Php Laravel身份验证检查
仅当用户未通过身份验证时,我的导航栏才应显示“注册”和“登录”按钮,否则将显示“注销”按钮Php Laravel身份验证检查,php,authentication,laravel-5.1,blade,Php,Authentication,Laravel 5.1,Blade,仅当用户未通过身份验证时,我的导航栏才应显示“注册”和“登录”按钮,否则将显示“注销”按钮 @if(Auth::check()) @否则 @恩迪夫 我知道该用户已通过身份验证,因为我从登录和注册页面获得了重定向,但它们仍显示在导航栏中。通过将Auth::check()更改为Auth::user()如何 @if(Auth::user()) @否则 @恩迪夫 将Auth::check()更改为Auth::user()如何 @if(Auth::user()) @否则 @恩迪夫 看来
@if(Auth::check())
@否则
@恩迪夫
我知道该用户已通过身份验证,因为我从登录和注册页面获得了重定向,但它们仍显示在导航栏中。通过将Auth::check()更改为Auth::user()如何
@if(Auth::user())
@否则
@恩迪夫
将Auth::check()更改为Auth::user()如何
@if(Auth::user())
@否则
@恩迪夫
看来您的逻辑在这里搞错了:
@if(Auth::check())
//this will show if the statement is true (user logged in)
<li><a class="navbarButton" href="auth/register"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a class="navbarButton" href="auth/login"><span class="glyphicon glyphicon-log-in"></span> Login</a> </li>
@else
//this will show if the statement is false (no user logged in)
<li><a class="navbarButton" href="auth/logout"><span class="glyphicon glyphicon-log-out"></span> Log out</a></li>
@endif
@if(Auth::check())
//这将显示该语句是否为真(用户已登录)
@否则
//这将显示该语句是否为false(没有用户登录)
@恩迪夫
如果将其反转为:
@if(Auth::check())
//this will show if the statement is true (user logged in)
<li><a class="navbarButton" href="auth/logout"><span class="glyphicon glyphicon-log-out"></span> Log out</a></li>
@else
//this will show if the statement is false (no user logged in)
<li><a class="navbarButton" href="auth/register"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a class="navbarButton" href="auth/login"><span class="glyphicon glyphicon-log-in"></span> Login</a> </li>
@endif
@if(Auth::check())
//这将显示该语句是否为真(用户已登录)
@否则
//这将显示该语句是否为false(没有用户登录)
@恩迪夫
看来您的逻辑在这里搞错了:
@if(Auth::check())
//this will show if the statement is true (user logged in)
<li><a class="navbarButton" href="auth/register"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a class="navbarButton" href="auth/login"><span class="glyphicon glyphicon-log-in"></span> Login</a> </li>
@else
//this will show if the statement is false (no user logged in)
<li><a class="navbarButton" href="auth/logout"><span class="glyphicon glyphicon-log-out"></span> Log out</a></li>
@endif
@if(Auth::check())
//这将显示该语句是否为真(用户已登录)
@否则
//这将显示该语句是否为false(没有用户登录)
@恩迪夫
如果将其反转为:
@if(Auth::check())
//this will show if the statement is true (user logged in)
<li><a class="navbarButton" href="auth/logout"><span class="glyphicon glyphicon-log-out"></span> Log out</a></li>
@else
//this will show if the statement is false (no user logged in)
<li><a class="navbarButton" href="auth/register"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a class="navbarButton" href="auth/login"><span class="glyphicon glyphicon-log-in"></span> Login</a> </li>
@endif
@if(Auth::check())
//这将显示该语句是否为真(用户已登录)
@否则
//这将显示该语句是否为false(没有用户登录)
@恩迪夫
有任何错误吗?没有,它正在工作,但是在身份验证之后,我应该只看到“注销”按钮,Auth类是全局的,不是吗?没有,它正在工作,但是在身份验证之后,我应该只看到“注销”按钮,Auth类是全局的,不是