laravel - Laravel Blade 仅在未登录时显示
问题描述
我正在使用 Laravel 的中间件,如果用户未通过身份验证,我会尝试使用空 div。否则,我试图拥有一个允许用户创建帐户的 div。我尝试了以下方法:
@auth
<div class="form-group col-md-6"></div>
@else
<div class="form-group col-md-6">
<h6>Create Account</h6>
</div>
@endauth
路线
Route::get('/checkout', 'CheckoutController@index')->name('checkout.index')->middleware('auth');
Route::get('/guestCheckout', 'CheckoutController@index')->name('guestCheckout.index');
CheckoutController.php
if (auth()->user() && request()->is('guestCheckout')) {
return redirect()->route('checkout.index');
}
以上不起作用,我尝试过删除历史记录,清除缓存等,但无济于事。建议?谢谢!
解决方案
如果用户未通过身份验证,则尝试使用空 div ...
您的刀片设置非常接近。尝试这个!
@auth
<!-- the user is authenticated -->
<div class="form-group col-md-6>
</div>
@endauth <!-- note the end auth -->
@guest
<!-- the user is NOT authenticated -->
<div class="form-group col-md-6>
<h6>Create Account</h6>
</div>
@endguest
您可以在此处阅读有关此内容的更多信息
至于您的控制器,请尝试使用:
if( Auth::check() )
{
// The user is authenticated..
} else {
// The user is NOT authenticated..
}
推荐阅读
- python - 如何在 Python 中导入 OpenSSL 以获取证书的序列号
- java - Akka 演员正在停止
- ios - 代码签名错误 命令/usr/bin/codedesign 失败,退出代码为 1
- python - 熊猫索引日期时间格式未提供所需的输出 Python3
- javascript - jquery 不适用于 diango
- css - 如何仅为角度6中的特定组件设置背景图像
- python - 删除第一列,然后将它们作为索引 pandas
- android - POST 登录后获取 JSON 数据
- php - Laravel:使用 SSL 证书上传到服务器
- firebase - 如何使用颤振从firebase数据库中获取值