Laravel文档阅读笔记-How to use @auth and @guest directives in Laravel

193 阅读1分钟

这个是我在阅读Laravel8中的文档时遇到的。在此阅读下@auth和@guest的用法。

下面将说明@auth和@guest在Laravel中的使用。

这两个关键字其实是代替@if、@endif的。

如下使用@if、@endif

@if(auth()->user())
 // The user is authenticated.
@endif

当用户有权限,就在blade中显示。

使用@auth和@guest可以简化成这样的:

@auth
 // The user is authenticated.
@endauth

@guest
 // The user is not authenticated.
@endguest

在个人项目中,我是这么用的:

it1995.cn
``` ```