PHPackages                             acacha/stateful-eloquent - 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. [Database &amp; ORM](/categories/database)
4. /
5. acacha/stateful-eloquent

ActiveLibrary[Database &amp; ORM](/categories/database)

acacha/stateful-eloquent
========================

State machines for Eloquent classes

0.1.8(9y ago)117.2k6MITPHPPHP &gt;=5.6.4

Since Nov 20Pushed 8y ago1 watchersCompare

[ Source](https://github.com/acacha/stateful-eloquent)[ Packagist](https://packagist.org/packages/acacha/stateful-eloquent)[ Docs](https://github.com/mikerice/stateful-eloquent)[ RSS](/packages/acacha-stateful-eloquent/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (10)Used By (0)

Laravel 5 Eloquent State Machine
================================

[](#laravel-5-eloquent-state-machine)

If you're familiar with my [AASM](https://github.com/aasm/aasm), then this is a similar take – just implemented in Laravel 5 for Eloquent classes.

References
----------

[](#references)

Forked from

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

[](#installation)

### Step 1: Install Through Composer

[](#step-1-install-through-composer)

```
composer require acacha/stateful-eloquent

```

### Step 2: Add the Service Provider

[](#step-2-add-the-service-provider)

```
Acacha\Stateful\Providers\StatefulServiceProvider::class,
```

### Step 3: Update your Eloquent Model

[](#step-3-update-your-eloquent-model)

Your models should use the Stateful trait and interface

```
use Acacha\Stateful\Traits\StatefulTrait;
use Acacha\Stateful\Contracts\Stateful;

class Transaction extends Model implements Stateful
{
    use StatefulTrait;
}
```

### Step 4: Create your Model States

[](#step-4-create-your-model-states)

Your models should have an array name `$states` that define your model states.

```
/**
 * Transaction States
 *
 * @var array
 */
protected $states = [
    'draft' => ['initial' => true],
    'processing',
    'errored',
    'active',
    'closed' => ['final' => true]
];
```

### Step 5: Create your Model State Transitions

[](#step-5-create-your-model-state-transitions)

```
/**
 * Transaction State Transitions
 *
 * @var array
 */
protected $transitions = [
    'process' => [
        'from' => ['draft', 'errored'],
        'to' => 'processing'
    ],
    'activate' => [
        'from' => 'processing',
        'to' => 'active'
    ],
    'fail' => [
        'from' => 'processing',
        'to' => 'errored'
    ],
    'close' => [
        'from' => 'active',
        'to' => 'close'
    ]
];

    /**
     * @return bool
     */
    protected function validateProcess()
    {
        $validate = true;
        if (!$validate) {
            $this->addValidateProcessMessage();
        }

        return $validate;
    }

    /**
     * @return bool
     */
    protected function validateActivate()
    {
        //dd("validateActivate");
        return true;
    }

    /**
     * @return bool
     */
    protected function validateFail()
    {
        //dd("validateFail");
        return true;
    }

    /**
     * @return bool
     */
    protected function validateClose()
    {
        //dd("validateClose");
        return true;
    }

    protected function beforeProcess() {
        //dd("doing something before entering processing state");
    }

    protected function afterProcess() {
        //dd("doing something after leaving processing state");
    }
```

Database configuration
----------------------

[](#database-configuration)

You model migration should have a state field like:

```
class CreateModelTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('model', function (Blueprint $table) {
            $table->increments('id');
            ...
            $table->string('state');
            ...
            $table->timestamps();
        });
    }
```

Usage
-----

[](#usage)

```
$transaction = new Transaction();

//Execute transition
$transaction->process();

//Check if a state is active (return true or false)
$transaction->active();
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.4% 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 ~21 days

Recently: every ~0 days

Total

9

Last Release

3285d ago

### Community

Maintainers

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

---

Top Contributors

[![acacha](https://avatars.githubusercontent.com/u/4015406?v=4)](https://github.com/acacha "acacha (19 commits)")[![mikerice](https://avatars.githubusercontent.com/u/138338?v=4)](https://github.com/mikerice "mikerice (3 commits)")

---

Tags

laraveleloquentstatemachine

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/acacha-stateful-eloquent/health.svg)

```
[![Health](https://phpackages.com/badges/acacha-stateful-eloquent/health.svg)](https://phpackages.com/packages/acacha-stateful-eloquent)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[bavix/laravel-clickhouse

Eloquent model for ClickHouse

72214.1k2](/packages/bavix-laravel-clickhouse)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)[mozex/laravel-scout-bulk-actions

A Laravel Scout extension for bulk importing and flushing of all models.

1033.4k](/packages/mozex-laravel-scout-bulk-actions)

PHPackages © 2026

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