mcpField
L
laravel-state-machines

laravel-state-machines

github.com/leeoveryDevelopment1545 installsUpdated 2w ago
Repository

About laravel-state-machines

laravel-state-machines is a skill for implementing complex state transitions in Laravel with Spatie Model States. It covers state and transition classes, validation, state-specific behavior, testing, and when a simple enum is sufficient.

Key features

  1. 01Spatie Model States setup
  2. 02State classes with behavior
  3. 03Validated transition classes
  4. 04State-specific methods
  5. 05Transition testing and enum guidance

Use cases

  1. 01Modeling validated order status changes
  2. 02Adding behavior tied to particular states
  3. 03Choosing between state machines and enums

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/leeovery/agentic-skills --skill laravel-state-machines

After installing, type/laravel-state-machinesin Claude Code to confirm it loaded.

Bundled filesreferences/state-management.md

Details

From the project README

Laravel State Machines

State machines with Spatie Model States for complex state transitions and validation.

Core Concept

state-management.md - State machine patterns:

  • Spatie Model States setup
  • State classes with behavior
  • Transition classes with validation
  • State-specific methods
  • When to use state machines vs simple enums
  • Testing state transitions

Pattern

// State classes
final class DraftOrderState extends OrderState
{
    public function canBeSubmitted(): bool
    {
        return true;
    }
}

final class PendingOrderState extends OrderState
{
    public function canBeSubmitted(): bool
    {
        return false;
    }
}

// Transition class
final class SubmitOrderTransition extends Transition
{
    public function handle(): OrderState
    {
        // Validation and side effects

        return new PendingOrderState($this->order);
    }
}

// Usage
$order->status->transitionTo(PendingOrderState::class);

Use state machines for complex state with validation, side effects, or state-specific behavior. Use simple enums for basic status fields.

Comments

Markdown supported