Skip to content
Back to skills

Laravel State Machines

ASecurity

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.

  • 666 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added February 9, 2026
documentationgophptesting

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill laravel-state-machines --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Laravel State Machines?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Laravel State Machines
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-laravel-state-machines/badge)](https://www.skillsdirectory.com/skills/majiayu000-laravel-state-machines)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: laravel-state-machines
description: 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.
---

# Laravel State Machines

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

## Core Concept

**[state-management.md](references/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

```php
// 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.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.