spatie/laravel-model-states
Add robust state behavior to Laravel Eloquent models using the state pattern and state machines. Represent each state as a class, cast states transparently to/from the database, and define clear, safe transitions with configurable state logic.
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?