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
- 01Spatie Model States setup
- 02State classes with behavior
- 03Validated transition classes
- 04State-specific methods
- 05Transition testing and enum guidance
Use cases
- 01Modeling validated order status changes
- 02Adding behavior tied to particular states
- 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-machinesAfter installing, type/laravel-state-machinesin Claude Code to confirm it loaded.
Bundled filesreferences/state-management.md
Details
From the project READMELaravel 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