tschucki / filament-workflows
将工作流添加到您的filament应用中
Requires
- php: ^8.1
- filament/filament: ^3.0
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
This package is auto-updated.
Last update: 2024-09-08 14:26:55 UTC
README
此插件允许您将工作流添加到您的filament应用中。您可以为工作流附加触发器和可调用的操作。当触发条件满足时,插件将自动执行操作。
目录
图片
安装
您可以通过composer安装此包
composer require tschucki/filament-workflows
您可以使用以下方式安装插件
php artisan filament-workflows:install
您可以使用以下方式手动发布和运行迁移
php artisan vendor:publish --tag="filament-workflows-migrations"
php artisan migrate
在您的 AdminPanelServiceProvider 中注册插件
use Tschucki\FilamentWorkflows\FilamentWorkflowsPlugin; ->plugins([ FilamentWorkflowsPlugin::make() ])
使用
基础知识
为了让您的模型使用工作流,您需要在模型中添加 InteractsWithWorkflows 特性。通过添加此特性,插件将自动为您的模型添加一个全局观察者。因此,当工作流匹配事件和触发条件时,工作流将执行操作。
将特性添加到您的模型中
use Tschucki\FilamentWorkflows\Concerns\InteractsWithWorkflow; class User extends Model { use InteractsWithWorkflow; }
创建一个操作
为了将操作附加到工作流中,您必须在 App\Jobs\Actions 文件夹中创建一个类。该类必须扩展 BaseAction 类。这要求您实现 handle 方法。此方法将在工作流执行时被调用。
操作类与作业非常相似。当操作执行时,模型将被传递到 __construct 方法。您可以使用模型执行任何操作。
插件会自动找到此类。因此,您不需要在任何地方注册它。
<?php namespace App\Jobs\WorkflowActions; use App\Models\User; use Illuminate\Database\Eloquent\Model; use Tschucki\FilamentWorkflows\WorkflowActions\BaseAction; class TestAction extends BaseAction { public User $user; public function __construct(User $user) { $this->user = $user; } public function handle(): void { \Log::info($this->user->name . ' was created at ' . $this->user->created_at); } // Will be later used in the Logs (coming soon) public function getActionName(): string { return 'Der Hackfleisch hassender Zerhacker'; } public function getActionDescription(): string { return 'Schneidet Kopfsalat. Und das nachts :)'; } public function getActionCategory(): string { return 'Default-Category'; } public function getActionIcon(): string { return 'heroicon-o-adjustments'; } }
就是这样。现在您可以为工作流创建和附加操作。
配置
定义可搜索字段
如果您不只想搜索 id,您可以使用模型中的 getTitleColumnForWorkflowSearch 函数在另一个字段中搜索。
public function getTitleColumnForWorkflowSearch(): ?string { return 'name'; }
最大搜索结果
如果您想更改模型的搜索结果数量,您可以发布配置文件并更改 workflows.search.max_results 的值(默认为100)。当您有许多模型且搜索速度慢时,这可能很有用。
<?php return [ 'search' => [ 'max_results' => 100, ] ];
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近的变化。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全漏洞
请审查 我们的安全策略 了解如何报告安全漏洞。
致谢
许可证
MIT许可证(MIT)。请参阅 许可证文件 了解更多信息。


