- 创建 SopTemplatePolicy 策略类 - 实现查看、创建、更新、删除权限 - 实现发布和归档权限 - 已发布的模板不能编辑和删除 - 只有草稿状态可以发布 - 只有已发布状态可以归档 - 在 AppServiceProvider 中注册策略
38 lines
824 B
PHP
38 lines
824 B
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Document;
|
|
use App\Models\SopTemplate;
|
|
use App\Observers\DocumentObserver;
|
|
use App\Policies\SopTemplatePolicy;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
// 配置 Carbon 使用中文
|
|
Carbon::setLocale('zh_CN');
|
|
|
|
// 注册文档观察者,用于自动管理 Meilisearch 索引
|
|
Document::observe(DocumentObserver::class);
|
|
|
|
// 注册策略
|
|
Gate::policy(SopTemplate::class, SopTemplatePolicy::class);
|
|
}
|
|
}
|