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(10mo ago)01MITPHPPHP ^8.1

Since Jun 27Pushed 10mo 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 1mo ago

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

28

—

LowBetter than 54% of packages

Maintenance54

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

318d 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

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M686](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M861](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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