php - IF 条件在刀片模板中的 @auth 下不起作用
问题描述
在我的项目中,用户可以通过 Facebook 或通过注册表单注册自己。
我在刀片模板上有一个按钮。我在限制它。如果来宾用户单击该按钮,则会出现一个模式,显示“请登录或注册”。但是,如果注册用户点击按钮,我想在这里用 if 条件进行以下两个检查:
- 如果电子邮件未验证且 Facebook_id 为空,则重定向到 verify.email 刀片。
- 如果电子邮件未验证但 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">×</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
解决方案
我自己想通了。
所以我根据问题提出了两个条件
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>
现在它工作完美!
推荐阅读
- python - 循环遍历多个数据帧并创建日期时间索引然后加入数据帧
- javascript - 如何使用 JS 随机化我的输入位置?
- sql - 如何计算带有滚动日期窗口的 SAS PROC SQL 的不同?
- wordpress - 更改特定 Woocommerce 产品类别存档页面的默认排序
- django - 在 CircleCI 上运行 Django - psycopg2.OperationalError:无法连接到服务器:连接被拒绝
- django - django 中用于 GenericRelation 的 DRF 可写序列化程序
- websphere-liberty - 在 server.xml 中使用 maven 过滤而不破坏 mvn liberty:dev
- c++ - 如何确保 boids 100% 的时间避开墙壁
- javascript - 希望在页面导航栏中突出显示滚动(从左到右)
- ocaml - 为什么流类型的这个 flatten 函数会给我这个错误?