laravel-state-machines

State machines using Spatie Model States for complex state transitions. Use when working with complex state management, state transitions, or when user mentions state machines, Spatie Model States, state transitions, transition validation.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "laravel-state-machines" with this command: npx skills add leeovery/claude-laravel/leeovery-claude-laravel-laravel-state-machines

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.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

laravel-testing

No summary provided by upstream source.

Repository SourceNeeds Review
General

laravel-quality

No summary provided by upstream source.

Repository SourceNeeds Review
General

laravel-architecture

No summary provided by upstream source.

Repository SourceNeeds Review