首页 > 解决方案 > 如何使用 @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

如果用户具有任何用户权限,则授予访问权限。

标签: laravel

解决方案


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

推荐阅读