spatie/laravel-model-states
Add state and state machine behavior to Laravel Eloquent models. Represent each state as a class, automatically serialize to/from the database, and perform clean, explicit transitions with configurable rules—ideal for workflows like payments, orders, and approvals.
Just like Laravel jobs, you're able to inject dependencies automatically in the handle() method of every transition.
class TransitionWithDependency extends Transition
{
// …
public function handle(Dependency $dependency)
{
// $dependency is resolved from the container
}
}
Note: be careful not to have too many side effects within a transition. If you're injecting many dependencies, it's probably a sign that you should refactor your code and use an event-based system to handle complex side effects.
How can I help you explore Laravel packages today?