PHPackages                             ilvalerione/state-machine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ilvalerione/state-machine

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ilvalerione/state-machine
=========================

State machine with laravel/eloquent integration

1.2.0(6y ago)16MITPHPPHP &gt;=7.1.0

Since Dec 17Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ilvalerione/state-machine)[ Packagist](https://packagist.org/packages/ilvalerione/state-machine)[ RSS](/packages/ilvalerione-state-machine/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

Laravel State Machine
=====================

[](#laravel-state-machine)

[![Latest Stable Version](https://camo.githubusercontent.com/3380e5fb025ac47bd5bda53f76509b71b54225492690d5c450ba505cf91be8d0/68747470733a2f2f706f7365722e707567782e6f72672f696c76616c6572696f6e652f73746174652d6d616368696e652f762f737461626c65)](https://packagist.org/packages/ilvalerione/state-machine)[![Total Downloads](https://camo.githubusercontent.com/7702a0646862cac4da2fa2a83827ccca6a41074f63694203ccdc27e7f064c437/68747470733a2f2f706f7365722e707567782e6f72672f696c76616c6572696f6e652f73746174652d6d616368696e652f646f776e6c6f616473)](https://packagist.org/packages/ilvalerione/state-machine)[![License](https://camo.githubusercontent.com/d7100ea8bb1bf69739b9334601609840206f12dc4d33e5319a8eccafe25cf801/68747470733a2f2f706f7365722e707567782e6f72672f696c76616c6572696f6e652f73746174652d6d616368696e652f6c6963656e7365)](https://packagist.org/packages/ilvalerione/state-machine)

- **Author:** Valerio Barbera -
- **Author Website:** www.logengine.dev

State machine for Laravel based applications.

Install
-------

[](#install)

`composer require ilvalerione/state-machine`

Config
------

[](#config)

`php artisan vendor:publish --provider="Aventure\StateMachine\ServiceProvider"`

This command publish a new configuration file in your `config` directory to list all state graphs that you want use in your application.

The default config file ships with a complete graph example.

Eloquent model integration
--------------------------

[](#eloquent-model-integration)

Add `HasStateMachine` trait to the eloquent model which you want manage its state:

```
class Order extends Model
{
    use HasStateMachine;

    ...
```

Assign state machine configuration to the model
-----------------------------------------------

[](#assign-state-machine-configuration-to-the-model)

```
class Order extends Model
{
    use HasStateMachine;

    /**
     * StateMachine configuration
     *
     * @return array
     */
    protected function stateMachineConfig() : array
    {
	    // This is the name of the graph in the "state-machine.php" config file
        return [
            'graph' => 'order',
        ];
    }
}
```

Default status
--------------

[](#default-status)

Use the eloquent `$attributes` property to set the default status of your object:

```
class Order extends Model
{
    use HasStateMachine;

    /**
     * Default model's attributes.
     *
     * @var array
     */
    protected $attributes = [
        'status' => 'pending'
    ];

    /**
     * StateMachine configuration
     *
     * @return array
     */
    protected function stateMachineConfig() : array
    {
	    // This is the name of the graph in the "state-machine.php" config file
        return [
            'graph' => 'order',
        ];
    }
}
```

Events
------

[](#events)

StateMachine provide you two main hooks to control the transition between states:

- Transitioning
- Transited

to point before and after every status change.

In the example below in your `EventServiceProvider` you can point before and after Order's "accept" transition.

```
class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
		'state_machine.transitioning.order.accept' => [
           ListenBeforeOrderIsAccepted::class,
        ],

        'state_machine.transited.order.accept' => [
            ListenAfterOrderIsAccepted::class,
        ],
    ];
}
```

The name of the events is dynamically composed using the convention below:

```
// Before trantion execution
state_machine.transitioning.[class_name].[transition_name]

// After trasition is executed
state_machine.transited.[model_class_name].[transition_name]

```

In this way you can attach your listener to a specific object when a particular transition happen.

LICENSE
=======

[](#license)

This package are licensed under the [MIT](LICENSE) license.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~82 days

Total

3

Last Release

2535d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/320345fbe48c7cff2b3a25992c8207e959ae7817fb2fb97bb176dc6e559aacf5?d=identicon)[valerione](/maintainers/valerione)

---

Top Contributors

[![ilvalerione](https://avatars.githubusercontent.com/u/13559278?v=4)](https://github.com/ilvalerione "ilvalerione (7 commits)")

---

Tags

phplaravelstate-machine

### Embed Badge

![Health badge](/badges/ilvalerione-state-machine/health.svg)

```
[![Health](https://phpackages.com/badges/ilvalerione-state-machine/health.svg)](https://phpackages.com/packages/ilvalerione-state-machine)
```

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[monicahq/laravel-cloudflare

Add Cloudflare ip addresses to trusted proxies for Laravel.

3372.7M4](/packages/monicahq-laravel-cloudflare)[mediconesystems/livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS

1.2k711.3k8](/packages/mediconesystems-livewire-datatables)[kra8/laravel-snowflake

Snowflake for Laravel and Lumen.

188402.3k6](/packages/kra8-laravel-snowflake)[bezhansalleh/filament-google-analytics

Google Analytics integration for FilamentPHP

205144.8k5](/packages/bezhansalleh-filament-google-analytics)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
