PHPackages                             hemp/machinery - 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. hemp/machinery

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

hemp/machinery
==============

Simple Laravel Eloquent model state machines

v0.2.1(1y ago)46301MITPHPCI passing

Since Dec 17Pushed 1y ago2 watchersCompare

[ Source](https://github.com/davidhemphill/machinery)[ Packagist](https://packagist.org/packages/hemp/machinery)[ RSS](/packages/hemp-machinery/feed)WikiDiscussions main Synced 1mo ago

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

HEMP Machinery 📠
================

[](#hemp-machinery-)

Machinery is tiny state machine package for Laravel. It allows you to manage a state machine for an attribute on one of your Eloquent models using PHP enumerations.

Machinery gives your backed enumeration superpowers by allowing you to specify the valid transitions between states.

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

[](#installation)

You can install the package via composer:

```
composer require hemp/machinery
```

Usage
-----

[](#usage)

First, create an enumeration that represents the states you wish to model and the valid transitions between them:

```
use Hemp\Machinery\MachineryState;
use Hemp\Machinery\MachineryEnumeration;

enum OrderStatus: string implements MachineryState
{
    use MachineryEnumeration;

    case Processing : 'processing';
    case Shipped : 'shipped';
    case Delivered : 'delivered';

    public static function transitions(): array
    {
        return [
            self::Processing->value => [
                self::Shipped
            ],
            self::Shipped->value => [
                self::Delivered
            ],
            self::Delivered->value => [
                // This is the final state...
            ]
        ];
    }
}
```

Now you can use the `OrderStatus` enumeration to manage transitions between states:

```
use Hemp\Machinery\Machinery;

OrderStatus::Processing->canTransitionTo(OrderStatus::Shipped); // true
OrderStatus::Processing->transitionTo(OrderStatus::Shipped); // state is now 'shipped'

OrderStatus::Shipped->canTransitionTo(OrderStatus::Delivered); // true
OrderStatus::Shipped->transitionTo(OrderStatus::Delivered); // state is now 'delivered'

OrderStatus::Delivered->canTransitionTo(OrderStatus::Processing); //
OrderStatus::Delivered->transitionTo(OrderStatus::Processing); // Throws an exception...
```

Using the state machine with Eloquent
-------------------------------------

[](#using-the-state-machine-with-eloquent)

Next, add a column to your Eloquent model's `casts` to store the state:

```
use Hemp\Machinery\Machinery;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    use Machinery;

    protected $casts = [
        'status' => OrderStatus::class
    ];
}
```

Now you can use the `OrderStatus` enumeration to manage the state of your `Order` model:

```
$order = Order::create([
    'status' => OrderStatus::Processing
]);

$order->status->is(OrderStatus::Processing); // true
$order->status->canTransitionTo(OrderStatus::Shipped); // true

$order->status->transitionTo('status', OrderStatus::Shipped, function (Order $order) {
    // Perform any side effects that need to happen before
    // the state change is persisted to the database...
    $order->status_changed_at = now();
});

$order->status->is(OrderStatus::Shipped); // true

$order->status->canTransitionTo('status', OrderStatus::Processing); // false

$order->status->transitionTo('status', OrderStatus::Delivered); // Throws an exception...
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance44

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 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 ~36 days

Total

3

Last Release

444d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d5351482a1d1514874fdec03f30b5074517ce7c0062059fd3c584cd259a613b?d=identicon)[davidhemphill](/maintainers/davidhemphill)

---

Top Contributors

[![davidhemphill](https://avatars.githubusercontent.com/u/58970?v=4)](https://github.com/davidhemphill "davidhemphill (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hemp-machinery/health.svg)

```
[![Health](https://phpackages.com/badges/hemp-machinery/health.svg)](https://phpackages.com/packages/hemp-machinery)
```

###  Alternatives

[yakamara/redaxo_yform

771.2k1](/packages/yakamara-redaxo-yform)[winter/wn-seo-plugin

Winter CMS plugin for managing SEO tags

106.3k](/packages/winter-wn-seo-plugin)

PHPackages © 2026

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