PHPackages                             pablopetr/laravel-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. pablopetr/laravel-state-machine

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

pablopetr/laravel-state-machine
===============================

Laravel-friendly state machine with class-based transitions and attribute binding

v1.0.0(1y ago)01MITPHPPHP ^8.1

Since Jun 27Pushed 1y agoCompare

[ Source](https://github.com/pablopetr/laravel-state-machine)[ Packagist](https://packagist.org/packages/pablopetr/laravel-state-machine)[ RSS](/packages/pablopetr-laravel-state-machine/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

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

[](#laravel-state-machine)

Laravel State Machine is a package that provides a elegant and easy way to create State Machines.

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

[](#installation)

```
composer require laravel/state-machine

```

Usage
-----

[](#usage)

To use the State Machine, you need to create a state machine class that extends the `StateMachine` class. You can define your states and transitions in this class.

```
use Laravel\StateMachine\StateMachine;

class OrderStateMachine extends StateMachine
{
    public static function field(): string
    {
        return 'state';
    }

    public static function initialState(): string
    {
        return 'pending';
    }

    protected function states(): array
    {
        return [
            'pending',
            'processing',
            'shipped',
            'delivered',
            'cancelled',
        ];
    }

    protected function transitions(): array
    {
        return [
            'process' => ['from' => 'pending', 'to' => 'processing'],
            'ship' => ['from' => 'processing', 'to' => 'shipped'],
            'deliver' => ['from' => 'shipped', 'to' => 'delivered'],
            'cancel' => ['from' => ['pending', 'processing'], 'to' => 'cancelled'],
        ];
    }

    public static function callbacks(): array
    {
        return [];
    }

    public static function guessModel(): string
    {
        return Order::class;
    }
}
```

You can then use this state machine in your application to manage the state of your orders.

```
$orderStateMachine = new OrderStateMachine();
$orderStateMachine->setState('pending');
$orderStateMachine->process(); // Changes state to 'processing'
$orderStateMachine->ship(); // Changes state to 'shipped'
$orderStateMachine->deliver(); // Changes state to 'delivered'
```

You can also check if a transition is allowed:

```
$orderStateMachine = new OrderStateMachine();
$orderStateMachine->setState('pending');
$isAllowed = $orderStateMachine->can('process'); // Returns true
$isAllowed = $orderStateMachine->can('ship'); // Returns false
$isAllowed = $orderStateMachine->can('deliver'); // Returns false
$isAllowed = $orderStateMachine->can('cancel'); // Returns true
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance49

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

372d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2410faa6e5e1489f8df772548ead47de77baaa00ea1ec4195e51d942279d997d?d=identicon)[pablopetr](/maintainers/pablopetr)

---

Top Contributors

[![pablopetr](https://avatars.githubusercontent.com/u/7885756?v=4)](https://github.com/pablopetr "pablopetr (2 commits)")

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[illuminate/redis

The Illuminate Redis package.

8314.6M374](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

244.6M137](/packages/illuminate-cookie)

PHPackages © 2026

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