changole/laravel-workflows
Composer 安装命令:
composer require changole/laravel-workflows
包简介
A Laravel-native workflow engine for modeling business processes with transitions, guards, and audit history.
README 文档
README
A lightweight, Laravel-native workflow engine for Eloquent models with explicit transitions, guard validation, events, and audit history.
Supports Laravel 10, 11, and 12.
Features
- Define explicit state transitions for Eloquent models.
- Enforce guard rules before transitions are applied.
- Emit transition lifecycle events for integrations and listeners.
- Keep audit history for transition activity.
- Configure behavior through publishable Laravel config.
Installation
You can install the package via composer:
composer require changole/laravel-workflows
Configuration
Publishing Config and Migrations
Publish the package configuration and migrations:
php artisan vendor:publish --tag=workflow-config php artisan vendor:publish --tag=workflow-migrations php artisan migrate
Config Example
return [ 'state_field' => 'state', 'auto_set_initial_state' => true, 'audit' => [ 'enabled' => true, ], ];
Usage
Define a Workflow
<?php namespace App\Workflows; use App\Models\Post; use Changole\Workflows\Core\WorkflowDefinition; use Changole\Workflows\Core\WorkflowContext; class PostWorkflow extends WorkflowDefinition { public function model(): string { return Post::class; } public function initialState(): string { return 'draft'; } public function transitions(): array { return [ $this->transition('submit')->from('draft')->to('pending'), $this->transition('approve') ->from('pending') ->to('approved') ->guard(fn (WorkflowContext $ctx) => (bool) ($ctx->meta['can_approve'] ?? false), 'Not allowed'), $this->transition('reject')->from('pending')->to('rejected'), ]; } }
Attach to a Model
<?php namespace App\Models; use Changole\Workflows\Traits\HasWorkflow; use Illuminate\Database\Eloquent\Model; class Post extends Model { use HasWorkflow; protected string $workflow = \App\Workflows\PostWorkflow::class; }
Apply Transitions
$post->workflow()->state(); $post->workflow()->can('submit'); $post->workflow()->apply('submit', auth()->user(), ['source' => 'api']);
Behavior
- Guard failures dispatch
WorkflowBlockedand throwGuardDeniedException. - Successful transitions dispatch
WorkflowTransitioningthenWorkflowTransitioned. - Audit entries are written to
workflow_transition_logswhenworkflow.audit.enabled = true.
Docker Test Workflow
make build
make install
make test
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
The MIT License (MIT). Please see License File for more information.
Credits
changole/laravel-workflows 适用场景与选型建议
changole/laravel-workflows 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 210 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 changole/laravel-workflows 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 changole/laravel-workflows 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 210
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 39
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-27