首页 > 解决方案 > IF 条件在刀片模板中的 @auth 下不起作用

问题描述

在我的项目中,用户可以通过 Facebook 或通过注册表单注册自己。

我在刀片模板上有一个按钮。我在限制它。如果来宾用户单击该按钮,则会出现一个模式,显示“请登录或注册”。但是,如果注册用户点击按钮,我想在这里用 if 条件进行以下两个检查:

  1. 如果电子邮件未验证且 Facebook_id 为空,则重定向到 verify.email 刀片。
  2. 如果电子邮件未验证但 Facebook_id 不为空,则重定向到促销刀片

现在来宾用户可以单击按钮,它会弹出登录/注册的弹出窗口,但是一旦用户完成登录/注册,其余代码将不起作用,并且不会显示注册用户的按钮。

完成登录/注册步骤后,当用户回到刀片时,没有任何按钮,不知道为什么。似乎@auth 下的代码不起作用。

    @guest
         <!-- Button trigger modal -->
             <button type="button" data-toggle="modal" data-target="#exampleModalCenter">
                        {{ __('Continue')}}
              </button>
         <!-- Modal -->
                        
        <div id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                            
       <div class="modal-dialog modal-dialog-centered" role="document">
         <div class="modal-content">
           <div class="modal-header">
             <h5 class="modal-title col-12 text-center" id="exampleModalLongTitle">Verification</h5>
               <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                 <span aria-hidden="true">&times;</span>
                </button>
                                    </div>

                <div class="modal-body">
                  <p>This page is restricted. Please <a href="{{route('login') }}" class="tooltip-test" title="Tooltip">Login</a> or <a href="{{route('getRegister')}}" class="tooltip-test" title="Tooltip">Register</a> to generate the code.</p>
                </div>
                
                <div class="modal-footer">
                  <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
            </div>
            </div>
            </div>

    @endguest

      @auth
      @if(\Auth::check() && \Auth::user()->email_verified_at == '' && \Auth::user()->provider_id == '')
        <a  href="{{route('auth.verify') }}">{{ __('Continue')}}</a>

   @elseif (\Auth::check() && \Auth::user()->email_verified_at == '' && \Auth::user()->provider_id != '')
        <a  href="{{route('dynamicDropDown-for-private-seller') }}">{{ __('Continue')}}</a>
       @endif

     @endauth

标签: phplaravel

解决方案


我自己想通了。

所以我根据问题提出了两个条件

1) If the email is not verified and Facebook_id is null then redirect to verify.email blade.

2) If the email is not verified but Facebook_id is not null then redirect to promotion blade

我忘了考虑如果用户电子邮件已经过验证并且他登陆页面怎么办,在这种情况下,没有为这样的用户定义任何操作,所以按钮没有显示。

我只是在 if 语句中添加了第三个条件,所以在 @endif 之前我只是添加了这一行

  @elseif(\Auth::user()->email_verified_at != '' && \Auth::user()->provider_id == '')
    <a  href="{{route('dynamicDropDown-for-private-seller') }}">{{ __('Continue')}}</a>

现在它工作完美!


推荐阅读