hyn/state-machine

Flexible state machine library that perfectly works with Laravels Eloquent models.
2,499 16
Install
composer require hyn/state-machine
Latest Version:4.0.0
PHP:>=8.1
Laravel:9 – 12
License:mit
Last Updated:Jan 7, 2026
Links: GitHub  ·  Packagist
Maintainer: Luceos

State machine

The state machine is a flexible library that helps you move Eloquent models from States through Transitions while emitting events along the way.

Example

Let's say we have a Cat, who does two things, being

In order to become Awake from his initial state being Asleep, the cat has to

Now if we look at the state machine definition we can see the above is perfectly mapped out.

Installation

composer require hyn/state-machine

Read more about installation and configuration on state-machine.readme.io.

Tests

Run the tests with:

vendor/bin/phpunit

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

641,106,524 9,700
laravel/framework

The Laravel Framework.

593,882,149 34,959
laravel/tinker

Powerful REPL for the Laravel framework.

502,645,077 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

418,291,778 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

394,964,158 4,660

Version History

Version Released PHP Laravel License
4.0.0 >=8.1 ^9.0 | ^10 | ^11 | ^12 mit
3.0.3 >=8.1 ^9.0 | ^10 mit
3.0.2 >=8.1 ^9.0 | ^10 mit
3.0.1 >=8.1 ^9.0 | ^10 mit
3.0.0 >=8.1 ^9.0 | ^10 mit