- How do I install caner/state-machine in a Laravel application?
- Install the package with Composer as caner/state-machine; it is MIT licensed and PSR-4 autoloaded. The integration surface is intentionally small, typically requiring a state column on your Eloquent model plus transition definitions. Before adopting it, verify the Laravel and PHP constraints in its composer.json and run a staging install against your target stack.
- Which Laravel and PHP versions does caner/state-machine support?
- The package's last release was on 2022-02-19, so compatibility with Laravel 10 or 11 and PHP 8.2 or 8.3 must be verified directly from composer.json and a staging install. Do not assume current framework support without testing. Pin the version with composer.lock discipline and confirm behavior across your next Laravel upgrade cycle.
- How do I define states and transitions for an Eloquent model?
- The package is designed to define states and transitions without bloating your Eloquent models, and it includes attribute casting for the state field. You add a state column to the model and declare the allowed transitions using the package's intuitive API. Keep the transition definitions close to the model or in a dedicated machine class, depending on the package's documented structure.
- Does caner/state-machine support guards or conditions for transitions?
- Yes, the package is described as allowing you to guard changes with conditions before a transition is allowed. Guards let you reject invalid transitions based on model attributes or business rules. Write tests for valid paths, invalid paths, and guard failures to confirm the behavior in your application.
- How does caner/state-machine handle transaction safety and concurrent transitions?
- The package is positioned as transaction-safe, which implies row-level locking and atomic transitions, but you must validate the exact implementation in the source. Check how locks are acquired, whether guards and side effects run inside or outside the database transaction, and what happens on lock timeout or deadlock. Run a concurrent transition test against the same row under load before relying on it in a transactional domain.
- Can I hook into transition events with caner/state-machine?
- Yes, the package includes hooks into transition events, which is useful for logging, notifications, and other side effects. Confirm whether those events fire inside or outside the database transaction and whether an afterCommit path exists for side effects. For production use, prefer deferring external side effects until after the transaction commits.
- Does caner/state-machine persist transition history or audit logs?
- The overview does not confirm built-in transition history or audit persistence, so inspect the source before assuming it exists. If auditability is required, plan to add your own transition history table or event listeners that record from-state, to-state, actor, and timestamp. State machine libraries often focus on enforcing transitions rather than providing a full audit trail.
- Is caner/state-machine safe to use in production?
- The maturity signals are weak: the last release was in February 2022, the repository has 51 stars, zero dependents, and a single maintainer. Treat it as a caution flag rather than a disqualifier, because the codebase is small and inspectable under a permissive MIT license. Review the concurrency semantics and test coverage, and be prepared to fork and own maintenance internally if adoption proceeds.
- How does caner/state-machine interact with Eloquent observers, model events, enum casts, or spatie/laravel-model-states?
- The package composes with Eloquent rather than dictating a full architecture, but its interaction with existing observers, model events, enum casts, and competing state packages must be tested. If your codebase already standardizes on enum casts or spatie/laravel-model-states, assess overlap before introducing a second abstraction. A proof of concept should verify that observers and model events do not double-fire or conflict with transition events.
- What is a safe migration path for adopting caner/state-machine?
- Start with a proof of concept on a single low-risk model: add the state column, define the machine, wrap transitions, and write tests for valid, invalid, and concurrent paths. Then pilot on one transactional domain with logging and metrics before broadening adoption. Build an explicit compatibility matrix for your Laravel and PHP versions, and treat a fork-or-own-maintenance decision as a hard checkpoint. Only expand rollout after those gates pass.