laravel - 如何使用 @can 检查 laravel 门中的两个权限?
问题描述
//e.g...
@can('view-post')
// show publish page
@endcan
//something like this.
@can('view-post') OR @can('publish-post')
// show publish page
@endcan
如果用户具有任何用户权限,则授予访问权限。
解决方案
https://laravel.com/docs/8.x/authorization
您还可以确定用户是否有权执行给定操作数组中的任何操作。为此,请使用
@canany
指令:
@canany(['update', 'view', 'delete'], $post)
<!-- The current user can update, view, or delete the post... -->
@elsecanany(['create'], \App\Models\Post::class)
<!-- The current user can create a post... -->
@endcanany
推荐阅读
- javascript - 在 Typescript 中,如何在存储然后从数组访问所述对象时维护对象类型?
- angular - Angular - 一次保存成两(2)个模型
- asp.net-core - Dotnet 监听 ASP.net 的 HTTPS 端口(端口 = 5001)
- angular - Angular 7 路由器:如果路由数据中未提供默认标题,则使用默认标题
- python - Python:循环中的向量化矩阵乘法?
- matlab - 如何在直方图中找到最高峰的 x 值?
- java - java.lang.IllegalStateException android.support.v4.media.session.MediaButtonReceiver.onReceive
- gradle - 使用 TeaVM 编译时出现 IllegalArgumentException
- sqlite - window.sqlitePlugin 未定义 - 但已安装 sqlite
- python - 是否可以将对象字段直接初始化为 __init__ 关键字参数?