PHPackages                             chareice/laravel-eloquent-fsm - 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. chareice/laravel-eloquent-fsm

ActiveLibrary

chareice/laravel-eloquent-fsm
=============================

A finite state machine works with laravel eloquent model

501[3 PRs](https://github.com/chareice/laravel-eloquent-fsm/pulls)PHP

Since Nov 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/chareice/laravel-eloquent-fsm)[ Packagist](https://packagist.org/packages/chareice/laravel-eloquent-fsm)[ RSS](/packages/chareice-laravel-eloquent-fsm/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

English | [中文](./README.zh-CN.md)

A finite state machine works with laravel eloquent model
========================================================

[](#a-finite-state-machine-works-with-laravel-eloquent-model)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require chareice/laravel-eloquent-fsm
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="eloquent-fsm-migrations"
php artisan migrate
```

Usage
-----

[](#usage)

```
use \Chareice\LaravelEloquentFSM\HasStateMachine;
use \Chareice\LaravelEloquentFSM\StateMachineModelInterface;

class Order extends Model implements StateMachineModelInterface {
    use HasStateMachine;

    public int $counter = 0;

    // define event
    public function events(): array
    {
        return [
            Event::builder()
                ->setName(OrderStateEvent::PAY)
                ->setFrom(OrderState::PENDING)
                ->setTo(OrderState::PAID)
                ->setAfter(function () {
                    $this->counter = 1;
                })
                ->build(),

            Event::builder()
                ->setName(OrderStateEvent::SHIP)
                ->setFrom(OrderState::PAID)
                ->setTo(OrderState::SHIPPED)
                ->build(),
        ];
    }
}

$order = Order::first();

// run event
$order->getStateMachine()->runEvent(OrderStateEvent::PAY);

// check new state
$order->getStateMachine()->getCurrentState(); // equals OrderState::PAID

// check event log
$order->stateMachineLogs()->first();
```

Testing
-------

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Chareice](https://github.com/chareice)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor1

Top contributor holds 57.9% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f75e764b0a3f4a3f92cbe0a60510bd45f3e24e9160a8c730f3fdd9c4d94ed398?d=identicon)[chareice](/maintainers/chareice)

---

Top Contributors

[![chareice](https://avatars.githubusercontent.com/u/1624785?v=4)](https://github.com/chareice "chareice (22 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

### Embed Badge

![Health badge](/badges/chareice-laravel-eloquent-fsm/health.svg)

```
[![Health](https://phpackages.com/badges/chareice-laravel-eloquent-fsm/health.svg)](https://phpackages.com/packages/chareice-laravel-eloquent-fsm)
```

PHPackages © 2026

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