Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Workflow Laravel Package

symfony/workflow

Symfony Workflow Component helps you model and run workflows or finite state machines in PHP. Define places, transitions, and guards to control state changes, track progress, and integrate with events for process automation.

View on GitHub
Deep Wiki
Context7

The Symfony Workflow component helps you model and execute workflows and finite state machines (FSM) in PHP applications. It provides a structured way to define states (places), transitions, and guards—making business processes explicit, testable, and easier to evolve.

Use it to control how an object moves through its lifecycle (e.g., draft → review → published) with clear rules and events you can hook into.

Features:

  • Define workflows and FSMs with places, transitions, and markings
  • Validate and apply transitions with guards and conditional logic
  • Dispatch events around transitions for listeners/subscribers
  • Visualize and debug with built-in dumpers (e.g., Graphviz)
  • Integrates cleanly with Symfony apps and standalone PHP projects
Frequently asked questions about Workflow
How do I integrate Symfony Workflow into a Laravel application?
Symfony Workflow is framework-agnostic but integrates smoothly with Laravel. Bind workflows to the container in `AppServiceProvider`, persist states to Eloquent models using `MethodMarkingStore`, and dispatch Laravel events on transitions. For example, trigger `OrderShipped` when an order transitions from `shipped` to `delivered`.
What Laravel versions and PHP versions does Symfony Workflow support?
Symfony Workflow supports Laravel as a standalone component and requires PHP 8.2+ (v7.x) or 8.4+ (v8.x). For older PHP (e.g., 8.1), use v6.4 of the component, but note that newer features like weighted transitions or BackedEnum support won’t be available. Laravel version compatibility is indirect—focus on PHP version support.
Can I use Symfony Workflow for order fulfillment workflows in Laravel?
Absolutely. Define states like `draft`, `review`, `shipped`, and `delivered` with transitions (e.g., `ship_order`). Use guards to enforce rules (e.g., `order.is_payable()`), persist states to an Eloquent model (e.g., `order.status`), and dispatch Laravel events like `OrderShipped` on transitions. The component handles complex pipelines like multi-step approvals.
How do I persist workflow states to a database in Laravel?
Use the `MethodMarkingStore` to sync workflow states to Eloquent model attributes. For example, map a workflow’s `marking` to a model’s `status` column. Configure the store in your workflow definition, and Laravel’s Eloquent will handle the database persistence automatically. For custom storage (e.g., Redis), implement a `MarkingStoreInterface`.
What are guards in Symfony Workflow, and how do I use them in Laravel?
Guards are conditions that validate whether a transition can occur. For example, a `publish_article` transition might require `article.is_reviewed()` AND `user.has_permission('publish')`. In Laravel, guards can call Eloquent methods, check auth (e.g., `auth()->user()->can('publish')`), or integrate with Laravel Policies for fine-grained control.
How do I test Symfony Workflow transitions in Laravel?
Test workflows by mocking the `Workflow` instance in PHPUnit and asserting transitions. For example, use `assertWorkflowTransitioned($workflow, $subject, 'draft', 'review')`. Test guards with mock data, and verify events are dispatched using Laravel’s `Events::assertDispatched()`. For integration tests, simulate full state paths (e.g., `draft → review → published`).
Can I visualize Symfony Workflow states in Laravel?
Yes. Use Symfony’s built-in `workflow:dump` CLI command to generate Graphviz or Mermaid diagrams. In Laravel, integrate the Symfony Profiler bundle to display workflow visualizations in the debug toolbar. For production, generate static diagrams via CLI and share them with stakeholders. No additional dependencies are needed beyond Symfony’s core tools.
What’s the performance impact of Symfony Workflow in Laravel?
Symfony Workflow adds minimal overhead—typically 5–10ms per workflow initialization. Benchmark in staging for your specific use case (e.g., 100 workflows/day vs. 100K). For high-throughput systems, cache workflow definitions or use lazy-loading. The component is optimized for clarity over raw speed, so prioritize readability and maintainability.
How do I handle concurrent workflow transitions in Laravel (e.g., two users approving an order)?
Concurrent transitions can cause race conditions. Use database transactions with `DB::transaction()` to ensure atomicity. For Eloquent, leverage optimistic locking (e.g., `increment('version')`) or pessimistic locks (`selectForUpdate()`). Symfony Workflow itself doesn’t handle concurrency—implement application-level locking in Laravel.
Are there alternatives to Symfony Workflow for Laravel workflows?
Alternatives include Laravel-specific packages like `spatie/laravel-workflow` (simpler, Laravel-focused) or `verot/flow` (lightweight). Symfony Workflow stands out for its maturity, guard conditions, event system, and FSM capabilities. Choose it if you need complex rules, auditability, or integration with Symfony’s ecosystem. For basic state machines, Spatie’s package may suffice.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport