- Can I use winzou/state-machine-bundle directly in Laravel without Symfony?
- No, this bundle is Symfony-centric and relies on AppKernel, Symfony’s DI container, and YAML config. Laravel’s architecture differs significantly, so you’d need to rewrite it as a Laravel package or use the underlying state-machine library directly. Consider alternatives like spatie/laravel-state-machines for native Laravel support.
- How do I define state machines in Laravel if this bundle isn’t compatible?
- For Laravel, use PHP arrays or config files instead of YAML. Alternatives like spatie/laravel-state-machines support Laravel’s config system and service container natively. You could also build a custom wrapper around the underlying state-machine library (e.g., `robrichards/state-machine`) to avoid Symfony dependencies.
- What Laravel versions does this bundle support?
- This bundle is Symfony-focused and doesn’t officially support Laravel. However, the underlying state-machine library (robrichards/state-machine) works with PHP 7.4+, which aligns with Laravel 8+. You’d need to adapt the bundle’s Symfony-specific code for Laravel compatibility.
- How do I configure state transitions and guards in Laravel if I adapt this bundle?
- Replace YAML config with Laravel’s `config/state-machines.php` or PHP classes. Guards and callbacks would use Laravel’s service container (e.g., `app()->make('MyService')`) instead of Symfony’s `@service.method` syntax. Example: Define transitions in a `StateMachineConfig` class with fluent methods for clarity.
- Are there Laravel-native alternatives to this bundle?
- Yes. Consider spatie/laravel-state-machines (Laravel-specific, uses PHP config) or verot/flow (event-driven FSM). Both avoid Symfony dependencies and integrate seamlessly with Laravel’s DI and config systems. Evaluate based on features like event listeners or database-backed state tracking.
- How do I handle callbacks (e.g., sending emails) in a Laravel-adapted version?
- Replace Symfony’s service-based callbacks with Laravel’s service resolution. For example, use `app()->make('MailService')->send()` in PHP callbacks instead of `@service.method`. For complex workflows, bind callbacks to Laravel events or queues (e.g., `dispatch(new SendEmail($article))`).
- Will this bundle work with Laravel’s Eloquent models?
- Not out of the box, but you could adapt it. The bundle expects a `state` property on your domain object. For Eloquent, map this to a database column (e.g., `protected $state = 'new'`). Alternatives like spatie/laravel-state-machines handle Eloquent migrations and model events automatically.
- How do I test state transitions in Laravel if I use this bundle?
- Mock the state machine’s core logic (e.g., `StateMachine::apply()`) and test transitions in PHPUnit. For Laravel-specific tests, use `RefreshDatabase` or `DatabaseTransactions` to verify state changes in your database. Alternatives like spatie/laravel-state-machines provide built-in testing helpers.
- Is this bundle actively maintained? Should I use it for production?
- The last release was in 2026, but there’s no visible maintenance (e.g., issues, PRs). For production, assess risks: Symfony dependencies, YAML config, and callback complexity. If critical, consider forking or building a Laravel adapter. Alternatives like spatie/laravel-state-machines are more actively maintained.
- How do I handle multiple state machines (e.g., Order payment + shipping) in Laravel?
- Define separate graphs in Laravel’s config (e.g., `payment_graph` and `shipping_graph`). Use traits or base classes to share common logic. Alternatives like spatie/laravel-state-machines support multiple machines per model out of the box. For complex workflows, consider event-driven architectures with Laravel’s event system.