symflow-laravel maintained by vandetho
Description
A Symfony-compatible workflow engine for Laravel. State machines, Petri nets, guards, events, validation, weighted arcs, middleware, and YAML/JSON/PHP import/export.
Author
Last update
2026/07/08 08:59
(dev-release-please--branches--main)
License
Downloads
0
Tags
SymFlow for Laravel
A Symfony-compatible workflow engine for Laravel. State machines, Petri nets, guards, events, weighted arcs, middleware, and YAML/JSON/PHP/Mermaid/Graphviz/SVG import/export.
Part of the SymFlow ecosystem. See also symflow for the TypeScript/Node.js version.
Installation
composer require vandetho/symflow-laravel
php artisan vendor:publish --tag=laraflow-config
Quick Start
Define a workflow in config/laraflow.php:
'workflows' => [
'order' => [
'type' => 'state_machine',
'marking_store' => ['type' => 'property', 'property' => 'status'],
'initial_marking' => ['draft'],
'places' => ['draft', 'submitted', 'approved', 'rejected', 'fulfilled'],
'transitions' => [
'submit' => ['from' => 'draft', 'to' => 'submitted'],
'approve' => ['from' => 'submitted', 'to' => 'approved'],
'reject' => ['from' => 'submitted', 'to' => 'rejected'],
'fulfill' => ['from' => 'approved', 'to' => 'fulfilled'],
],
],
],
Use the Eloquent trait:
use Laraflow\Eloquent\HasWorkflowTrait;
class Order extends Model
{
use HasWorkflowTrait;
protected function getDefaultWorkflowName(): string
{
return 'order';
}
}
$order->applyTransition('submit');
$order->canTransition('approve'); // true/false
Or use the Facade:
use Laraflow\Facades\Laraflow;
$workflow = Laraflow::get('order');
$workflow->apply($order, 'submit');
Features
- Two workflow types --
state_machineandworkflow(Petri net with parallel states) - Symfony event order --
guard > leave > transition > enter > entered > completed > announce - Subject-driven API -- mirrors Symfony's
$workflow->apply($entity, 'submit')pattern - Marking stores --
propertyandmethodstores, or implement your own - Pluggable guards --
GuardEvaluatorInterfacefor custom authorization - Structured guard results -- return
GuardResult::deny($reason, $code)so blockers carry a human-readable reason - Blockable Guard event -- listeners can veto a transition via
$event->setBlocked(true, reason, code) - Listener scoping & priority --
on()accepts an optional transition name and priority for declarative ordering - Listener error modes --
ListenerErrorMode::Throw / Collect / Swallowcontrols how listener exceptions surface - Weighted arcs --
consumeWeight/produceWeightfor multi-token transitions - Middleware -- wrap
apply()with logging, transactions, metrics - Validation -- 8 error types including BFS reachability analysis
- Pattern analysis -- AND-split, AND-join, OR-split, XOR detection
- Import/Export -- YAML (Symfony-compatible), JSON, PHP codegen, Mermaid, Graphviz DOT, SVG (auto-layout, dark/light theme)
- Eloquent trait --
HasWorkflowTraitfor model integration - Laravel events -- 7 event classes for the full transition lifecycle
- Artisan commands --
laraflow:validate,laraflow:mermaid,laraflow:dot
Examples
End-to-end Laravel apps built on symflow-laravel:
| Repo | What it shows |
|---|---|
| symflow-laravel-expense-approval | Multi-stage expense approval as a Petri net — parallel legal/finance/manager review, Livewire 3 + Tailwind, Fly.io-ready |
| symflow-laravel-issue-tracker | Issue tracker with parallel code-review + qa-review tracks — Petri net + Livewire, Fly.io-ready |
| symflow-laravel-order-lifecycle | Three concurrent workflows on one Order model — order_lifecycle + order_payment state machines and an order_fulfillment Petri net (parallel pick + pack), shared guard + audit middleware |
Documentation
| Guide | Description |
|---|---|
| Getting Started | Installation, first workflow, Eloquent trait |
| Engine API | WorkflowEngine, guards, validation, pattern analysis |
| Subject API | Workflow facade, marking stores, config-driven workflows |
| Weighted Arcs | Multi-token transitions |
| Middleware | Lifecycle hooks, transactions, logging |
| Events | Symfony event order, Laravel event integration |
| Artisan Commands | validate, mermaid, dot |
| Persistence Formats | YAML, JSON, PHP, Mermaid, Graphviz |
License
MIT