digitalcloud / nova-permission-tool
一个Laravel Nova权限工具。
v1.6
2019-04-21 09:41 UTC
Requires
- php: >=7.1.0
- spatie/laravel-permission: ^2.22
This package is auto-updated.
Last update: 2024-09-21 21:47:11 UTC
README
此工具允许您创建和管理nova资源的规则和权限。安装后,将为所有可用资源和资源操作生成默认的nova资源权限。
需求与依赖
此工具使用 Spatie Permission 包。
安装
您可以通过composer安装此包
composer require digitalcloud/nova-permission-tool
您可以使用以下命令发布迁移
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"
迁移发布后,您可以通过运行迁移来创建角色和权限表
php artisan migrate
用法
您必须在Nova中注册此工具。通常在app/Providers/NovaServiceProvider.php中的tools方法中完成。
use DigitalCloud\PermissionTool\PermissionTool; // .... public function tools() { return [ // ... new PermissionTool(), // ... ]; }
要允许工具生成权限动作,您需要设置动作名称。没有名称的动作将不会自动生成。
<?php namespace App\Nova\Actions; use Laravel\Nova\Actions\Action; class YourAction extends Action { // ... public $name = 'send email'; // ... }
然后在资源中可以授权该动作
<?php namespace App\Nova; use App\Nova\Actions\YourAction; use Illuminate\Support\Facades\Gate; use Illuminate\Http\Request; class Quotation extends Resource { // ... public function actions(Request $request) { return [ (new YourAction())->canSee(function ($request) { return Gate::check('send email'); // the same name of the action })->canRun(function ($request) { return Gate::check('send email'); // the same name of the action }) ]; } // ... }