-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Advanced State Machine implementation for Laravel applications
Laravel Statecraft 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.
- π YAML-Driven: Define state machines in simple, readable 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 & Actions: Pre/post transition validation and processing
- π Model Integration: Seamless Eloquent model integration
- π¨ CLI Tools: Artisan commands for state machine management
- π Visualization: Export state machines to Mermaid diagrams
- π§ͺ Test-Friendly: Built-in testing utilities
composer require grazulex/laravel-statecraft
php artisan statecraft:make OrderStateMachine --model=Order
# 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
- name: ship
from: paid
to: shipped
action: CreateShipment
use Grazulex\LaravelStatecraft\HasStateMachine;
class Order extends Model
{
use HasStateMachine;
protected $stateMachine = 'OrderStateMachine';
}
$order = Order::create(['amount' => 100]);
// Check current state
$order->getCurrentState(); // 'pending'
// Transition to next state
$order->transitionTo('pay');
$order->getCurrentState(); // 'paid'
// Check if transition is possible
$order->canTransitionTo('ship'); // true
Laravel Statecraft excels in scenarios requiring complex state management:
- π¦ Order Processing - E-commerce order workflows with payment, fulfillment, and shipping
- π₯ User Registration - Multi-step user onboarding and verification processes
- π Approval Systems - Document review, request approval, and content moderation
- π° Content Publishing - Article drafting, review, and publication workflows
- π³ Subscription Management - User subscription lifecycle and payment handling
Ready to dive deeper? Our comprehensive guides will get you up to speed:
- Installation & Setup - Install and configure Laravel Statecraft
- Basic Usage Guide - Learn the fundamentals
- Your First State Machine - Step-by-step tutorial
- YAML Configuration - Complete YAML syntax reference
- Guards & Actions - Implement conditional logic and side effects
- Events System - Handle state change events
- State History - Track and audit state changes
- Console Commands - CLI tools and utilities
- Testing Guide - Test your state machines effectively
- Order Workflow Example - Complete e-commerce order processing
- Article Publishing Example - Content management workflow
- User Subscription Example - Subscription lifecycle management
- Event Usage Example - Working with state machine events
- Examples Collection - More real-world examples
- Install Laravel Statecraft and get up and running in minutes
- Follow the Basic Usage Guide to understand core concepts
- Explore Examples to see real-world implementations
- Join our Community and contribute to the project
Ready to transform your Laravel application's state management? Let's get started! π―
π― Laravel Statecraft - Advanced State Machine Implementation for Laravel
Navigate: π Home | π¦ Installation | π Basic Guide | π YAML Config | π‘ Examples
Resources: π‘οΈ Guards & Actions | π― Events | π State History | π§ͺ Testing | π¨ Commands
π Community Resources:
Made with β€οΈ for the Laravel community β’ Contribute β’ License