PHPackages                             grazulex/laravel-statecraft - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. grazulex/laravel-statecraft

ActiveLibrary[Testing &amp; Quality](/categories/testing)

grazulex/laravel-statecraft
===========================

A declarative and testable way to model entity state transitions (orders, documents, processes…) with guard conditions, actions, and events.

v1.3.0(9mo ago)95MITPHPPHP ^8.3CI passing

Since Jul 20Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/Grazulex/laravel-statecraft)[ Packagist](https://packagist.org/packages/grazulex/laravel-statecraft)[ Docs](https://github.com/grazulex/laravel-statecraft)[ RSS](/packages/grazulex-laravel-statecraft/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Statecraft
==================

[](#laravel-statecraft)

[![Laravel Statecraft](new_logo.png)](new_logo.png)

Advanced State Machine implementation for Laravel applications. Declarative state management with support for conditions, actions, and complex workflows through YAML configuration.

[![Latest Version](https://camo.githubusercontent.com/912b2ca0e20859170ad57eeade820395c2e49f92a26075933355d7a53c008e94/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772617a756c65782f6c61726176656c2d737461746563726166742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grazulex/laravel-statecraft)[![Total Downloads](https://camo.githubusercontent.com/887ae3c76f28545066cf059275cd4671126c9d1983fd5872926d8f88bf9e4713/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772617a756c65782f6c61726176656c2d737461746563726166742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grazulex/laravel-statecraft)[![License](https://camo.githubusercontent.com/c47be38ea951aa5af98bf4aab966837c10d185fd06a9598b7a7af19f9e0f2280/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6772617a756c65782f6c61726176656c2d737461746563726166742e7376673f7374796c653d666c61742d737175617265)](https://github.com/Grazulex/laravel-statecraft/blob/main/LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/fb76526e77f349cf29bd22b12f38b5bac851081633a12fbdc263d07f4dfafe67/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6772617a756c65782f6c61726176656c2d737461746563726166742e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Laravel Version](https://camo.githubusercontent.com/7592d340e2de1142fa869382b819654d6a0bf7baf8e3c8aded777d652d68c01a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31322e782d6666326432303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://laravel.com/)[![Tests](https://camo.githubusercontent.com/57dc24ef0b0eaa1839ed68e762dea6f4e1e714dd29ed3a1d0387208da66d28ca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6772617a756c65782f6c61726176656c2d737461746563726166742f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/Grazulex/laravel-statecraft/actions)[![Code Style](https://camo.githubusercontent.com/161d70e6871f808e0439b3e7a86540993ae98775540b5a2e78226000e3c419c7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d70696e742d3030303030303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://github.com/laravel/pint)

📖 Table of Contents
-------------------

[](#-table-of-contents)

- [Overview](#overview)
- [✨ Features](#-features)
- [📦 Installation](#-installation)
- [🚀 Quick Start](#-quick-start)
- [📚 Complete Documentation](#-complete-documentation)
- [💡 Examples &amp; Use Cases](#-examples--use-cases)
- [🔧 Requirements](#-requirements)
- [🧪 Testing](#-testing)
- [🚀 Performance](#-performance)
- [🤝 Contributing](#-contributing)
- [🔒 Security](#-security)
- [📄 License](#-license)

Overview
--------

[](#overview)

Laravel Statecraft is a powerful state machine implementation for Laravel that provides declarative state management through YAML configuration. Build complex workflows with conditional transitions, guards, actions, and comprehensive state tracking.

**Perfect for order processing, user workflows, approval systems, and any application requiring sophisticated state management.**

### 🎯 Use Cases

[](#-use-cases)

Laravel Statecraft is perfect for:

- **Order Processing** - Complex e-commerce order workflows
- **User Registration** - Multi-step user onboarding flows
- **Approval Systems** - Document or request approval workflows
- **Content Management** - Publishing and moderation workflows
- **Business Processes** - Any multi-state business logic

✨ Features
----------

[](#-features)

- 🚀 **Declarative Configuration** - Define state machines in YAML files
- 🔄 **Flexible Transitions** - Conditional transitions with guards and actions
- 🎯 **Event System** - Built-in events for state changes and transitions
- 📊 **State History** - Track all state changes with timestamps
- 🛡️ **Guards &amp; Actions** - Pre/post transition validation and processing
- 🔗 **Model Integration** - Seamless Eloquent model integration
- 📋 **YAML Support** - Human-readable state machine definitions
- 🎨 **Artisan Commands** - CLI tools for state machine management
- ✅ **Validation** - Comprehensive state machine validation
- 📈 **Visualization** - Export state machines to Mermaid diagrams
- 🧪 **Test-Friendly** - Built-in testing utilities
- ⚡ **Performance** - Optimized for speed with caching support

📦 Installation
--------------

[](#-installation)

Detailed installation instructions are available in our wiki: **[📦 Installation &amp; Setup](https://github.com/Grazulex/laravel-statecraft/wiki/Installation-&-Setup)**

Quick install via Composer:

```
composer require grazulex/laravel-statecraft
```

> **💡 Auto-Discovery**
> The service provider will be automatically registered thanks to Laravel's package auto-discovery.

Publish configuration:

```
php artisan vendor:publish --tag=statecraft-config
```

Publish migrations (if using history tracking):

```
php artisan vendor:publish --tag=statecraft-migrations
php artisan migrate
```

🚀 Quick Start
-------------

[](#-quick-start)

For a complete getting started guide, visit: **[🚀 Basic Usage Guide](https://github.com/Grazulex/laravel-statecraft/wiki/Basic-Usage-Guide)**

### 1. Create a State Machine Definition

[](#1-create-a-state-machine-definition)

```
php artisan statecraft:make OrderStateMachine --model=Order
```

### 2. Define Your State Machine in YAML

[](#2-define-your-state-machine-in-yaml)

```
# state-machines/OrderStateMachine.yaml
name: OrderStateMachine
model: App\Models\Order
initial_state: pending

states:
  - name: pending
    description: Order is pending payment
  - name: paid
    description: Order has been paid
  - name: shipped
    description: Order has been shipped

transitions:
  - name: pay
    from: pending
    to: paid
    guard: PaymentGuard
    action: ProcessPayment
```

### 3. Add the Trait to Your Model

[](#3-add-the-trait-to-your-model)

```
use Grazulex\LaravelStatecraft\HasStateMachine;

class Order extends Model
{
    use HasStateMachine;

    protected $stateMachine = 'OrderStateMachine';
}
```

### 4. Use State Transitions

[](#4-use-state-transitions)

```
// Create a new order (starts in 'pending' state)
$order = Order::create(['total' => 100.00]);

// Transition to next state
$order->transition('pay'); // Moves to 'paid' state

// Check current state
echo $order->currentState(); // 'paid'
```

📚 Complete Documentation
------------------------

[](#-complete-documentation)

Our comprehensive documentation is available in the GitHub Wiki:

### 🏗️ Core Concepts

[](#️-core-concepts)

- **[📄 YAML Configuration](https://github.com/Grazulex/laravel-statecraft/wiki/YAML-Configuration)** - Complete YAML syntax and options
- **[🛡️ Guards &amp; Actions](https://github.com/Grazulex/laravel-statecraft/wiki/Guards-&-Actions)** - Pre/post transition logic
- **[🎯 Events System](https://github.com/Grazulex/laravel-statecraft/wiki/Events-System)** - State change events and listeners
- **[📊 State History](https://github.com/Grazulex/laravel-statecraft/wiki/State-History)** - Track and audit state changes

### 🔧 Advanced Topics

[](#-advanced-topics)

- **[⚙️ Configuration Guide](https://github.com/Grazulex/laravel-statecraft/wiki/Configuration-Guide)** - Package configuration options
- **[🎨 Console Commands](https://github.com/Grazulex/laravel-statecraft/wiki/Console-Commands)** - Artisan commands reference
- **[🧪 Testing Guide](https://github.com/Grazulex/laravel-statecraft/wiki/Testing-Guide)** - Testing your state machines

### 📖 Getting Started

[](#-getting-started)

- **[🏠 Wiki Home](https://github.com/Grazulex/laravel-statecraft/wiki/Home)** - Complete documentation homepage
- **[📦 Installation &amp; Setup](https://github.com/Grazulex/laravel-statecraft/wiki/Installation-&-Setup)** - Detailed installation guide
- **[🚀 Basic Usage Guide](https://github.com/Grazulex/laravel-statecraft/wiki/Basic-Usage-Guide)** - Step-by-step tutorial

💡 Examples &amp; Use Cases
--------------------------

[](#-examples--use-cases)

Explore real-world implementations and patterns:

- **[📚 Examples Collection](https://github.com/Grazulex/laravel-statecraft/wiki/Examples-Collection)** - Complete examples overview
- **[📦 Order Workflow Example](https://github.com/Grazulex/laravel-statecraft/wiki/Order-Workflow-Example)** - E-commerce order processing
- **[📰 Article Publishing Example](https://github.com/Grazulex/laravel-statecraft/wiki/Article-Publishing-Example)** - Content management workflow
- **[💳 User Subscription Example](https://github.com/Grazulex/laravel-statecraft/wiki/User-Subscription-Example)** - Subscription lifecycle management
- **[🎯 Event Usage Example](https://github.com/Grazulex/laravel-statecraft/wiki/Event-Usage-Example)** - Advanced event handling

🔧 Requirements
--------------

[](#-requirements)

- PHP 8.2 or higher
- Laravel 11.x or higher
- Optional: Redis for caching (recommended for production)

🧪 Testing
---------

[](#-testing)

Comprehensive testing guide: **[🧪 Testing Guide](https://github.com/Grazulex/laravel-statecraft/wiki/Testing-Guide)**

```
composer test
composer test:coverage
composer test:types
```

🚀 Performance
-------------

[](#-performance)

Laravel Statecraft is optimized for production use with caching support and minimal overhead. See our **[⚙️ Configuration Guide](https://github.com/Grazulex/laravel-statecraft/wiki/Configuration-Guide)** for performance optimization tips.

🤝 Contributing
--------------

[](#-contributing)

We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Before contributing:

1. Read our [Code of Conduct](CODE_OF_CONDUCT.md)
2. Check the [issue tracker](https://github.com/Grazulex/laravel-statecraft/issues)
3. Review our **[📚 Complete Documentation](https://github.com/Grazulex/laravel-statecraft/wiki)**

🔒 Security
----------

[](#-security)

If you discover a security vulnerability, please send an e-mail via the [security policy](SECURITY.md). All security vulnerabilities will be promptly addressed.

📄 License
---------

[](#-license)

Laravel Statecraft is open-sourced software licensed under the [MIT license](LICENSE.md).

---

**Made with ❤️ for the Laravel community**

### Resources

[](#resources)

- [📖 Documentation](https://github.com/Grazulex/laravel-statecraft/wiki)
- [💬 Discussions](https://github.com/Grazulex/laravel-statecraft/discussions)
- [🐛 Issue Tracker](https://github.com/Grazulex/laravel-statecraft/issues)
- [📦 Packagist](https://packagist.org/packages/grazulex/laravel-statecraft)

### Community Links

[](#community-links)

- [CODE\_OF\_CONDUCT.md](CODE_OF_CONDUCT.md) - Our code of conduct
- [CONTRIBUTING.md](CONTRIBUTING.md) - How to contribute
- [SECURITY.md](SECURITY.md) - Security policy
- [RELEASES.md](RELEASES.md) - Release notes and changelog

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance57

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

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

296d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/888105bd54b6b7f7905523a16a1d08eebc2e5d39b19a4c174b5961bb4d52929b?d=identicon)[Grazulex](/maintainers/Grazulex)

---

Top Contributors

[![Grazulex](https://avatars.githubusercontent.com/u/4521546?v=4)](https://github.com/Grazulex "Grazulex (66 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (24 commits)")

---

Tags

laravelpackagephpstate-machinepestlaravelworkflowclean codemodularflowpipelinelaravel12php8.3stepsconditionaltraceableflowpipe

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/grazulex-laravel-statecraft/health.svg)

```
[![Health](https://phpackages.com/badges/grazulex-laravel-statecraft/health.svg)](https://phpackages.com/packages/grazulex-laravel-statecraft)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[laravel/sail

Docker files for running a basic Laravel application.

1.9k186.9M1.0k](/packages/laravel-sail)[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)[laravel/roster

Detect packages &amp; approaches in use within a Laravel project

15410.4M7](/packages/laravel-roster)[grazulex/laravel-devtoolbox

Swiss-army artisan CLI for Laravel — Scan, inspect, debug, and explore every aspect of your Laravel application from the command line.

1535.4k](/packages/grazulex-laravel-devtoolbox)

PHPackages © 2026

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