vladout / 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-19 16:25:31 UTC
README
此工具允许您创建和管理 nova 资源规则和权限。安装后,将为所有可用资源及其操作生成默认 nova 资源权限。
要求与依赖
此工具使用 Spatie Permission 包。
安装
您可以通过 composer 安装此包。
composer require vladout/nova-permission-tool
您可以使用以下命令发布迁移:
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"
迁移发布后,您可以通过运行迁移来创建角色和权限表
php artisan migrate
用法
您必须将工具注册到 Nova 中。通常在 NovaServiceProvider 的 tools 方法中完成,位于 app/Providers/NovaServiceProvider.php。
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 }) ]; } // ... }