nganthoiba/laravel-dynamic-workflow
Composer 安装命令:
composer require nganthoiba/laravel-dynamic-workflow
包简介
A dynamic graph-based workflow engine and visual designer for Laravel.
README 文档
README
A powerful, dynamic graph-based workflow engine and visual designer for Laravel. This package allows you to define complex business processes using a visual interface and execute them with a robust, event-driven engine.
Features
- Visual Workflow Designer: Integrated drag-and-drop designer powered by LogicFlow.
- Dynamic Graph Engine: Support for branching, conditions, and custom node handlers.
- Customizable Actions (Hooks): Define business logic as
StepActionclasses that trigger during transitions. - Role-Based Routing: Assign workflow steps to specific user roles.
- Condition Support: Dynamic branching based on data-driven conditions.
- Vendor Agnostic: easily integrates with your existing User and Role models.
Installation
Install the package via composer:
composer require nganthoiba/laravel-dynamic-workflow
Publish the configuration, assets, and views:
php artisan vendor:publish --provider="Workflow\Providers\WorkflowServiceProvider"
Run the migrations:
php artisan migrate
Configuration
Update config/workflow.php to map your application's identity models:
'models' => [ 'role' => \App\Models\Role::class, 'user' => \App\Models\User::class, ],
Usage Guide
1. Defining Workflow Actions (Hooks)
Hooks in this package are implemented as StepAction classes. These classes contain the business logic that should execute when a workflow reaches or leaves a specific step.
Create a class that implements Workflow\Core\Contracts\StepActionInterface:
namespace App\Workflow\Actions; use Workflow\Core\Contracts\StepActionInterface; use Workflow\Models\WorkflowInstanceStep; use Illuminate\Database\Eloquent\Model; class ApproveOrderAction implements StepActionInterface { public function validate(array $data): array { return validator($data, [ 'remarks' => 'nullable|string|max:500', ])->validate(); } public function execute(array $data, Model $model, WorkflowInstanceStep $workflowInstanceStep): void { // $model is your business model (e.g., Order) $model->update(['status' => 'approved']); // Log the action or send notifications logger()->info("Order {$model->id} approved by user."); } }
2. Registering Actions
Register your actions in config/workflow.php so they appear in the Designer:
'workflow_actions' => [ 'approve_order' => [ 'label' => 'Approve Order', 'view' => 'approve_order_view', // Blade view for the task UI 'action' => \App\Workflow\Actions\ApproveOrderAction::class, ], ],
3. Visual Designing
- Access the designer at
/workflow/processes. - Create a new process.
- Use the Launch Designer button to open the visual editor.
- Drag nodes onto the canvas:
- Step Nodes: Assign them a "Workflow Action" (hook) and "Authorized Roles".
- Condition Nodes: Define branching logic based on the data context.
- Connect nodes using arrows to define the flow.
4. Starting a Workflow
To start a workflow for a specific business model instance:
use Workflow\Models\Process; use Workflow\Services\WorkflowInstanceService; $process = Process::where('code', 'ORDER_APPROVAL')->first(); $order = Order::find(1); $service = app(WorkflowInstanceService::class); $instance = $service->initialize($process, $order);
5. Handling Tasks (The Inbox)
The package provides a built-in Inbox UI at /workflow/inbox.
When a user submits a task through the UI:
- The
WorkflowControllerresolves theStepActionassociated with the current step. - It runs the
validate()method. - If valid, it runs the
execute()method (the "hook"). - Finally, the engine moves the workflow to the next step based on the graph definition.
Customization
Custom Node Handlers
If you need custom routing logic (e.g., waiting for multiple parallel approvals), you can extend Workflow\Core\Handlers\NodeHandler and register it in the StepFactory.
UI Layout
The package views extend workflow::task_layout. You can publish and customize this layout to match your application's theme.
License
The MIT License (MIT).
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2026-05-12