laravel-state-machines

Implement type-safe state machines in Laravel using Spatie Model States.

1|Updated Oct 10, 2025
One-click install
npx skills add https://github.com/nextplus896/durra-alaseel --skill laravel-state-machines
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-state-machines
Source: https://github.com/nextplus896/durra-alaseel/tree/main/.github/skills/claude-laravel/laravel-state-machines
Command: npx skills add https://github.com/nextplus896/durra-alaseel --skill laravel-state-machines

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill enables developers to implement robust, type-safe state machines in Laravel using the Spatie Model States package.

Core Features & Use Cases

  • Spatie Model States integration with defined states, transitions, and validations
  • State-specific behavior, guards, and transition side effects
  • Type-safe checks and model helpers to orchestrate transitions

Quick Start

Install and configure the Spatie Model States package in your Laravel project. Define a state hierarchy with a base OrderState and concrete states, plus Transition classes for each change. Use the HasStates trait on your models and expose transition methods that call transitionTo(...).

Frequently Asked Questions about laravel-state-machines

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement state machines in Laravel using Spatie Model States?

To implement Laravel state machines with Spatie Model States, install the package, define a base state and concrete state classes, create transition classes, and use the HasStates trait on your models. This provides type-safe state checks and transition orchestration.

When should I use state transitions instead of simple status columns in Laravel?

You should use Laravel state transitions when your models require type-safe state checks, transition guards, validation rules, or side effects. State machines enforce valid transitions and encapsulate state-specific behavior, preventing invalid status changes that simple columns cannot restrict.

How do I add guards and side effects to Laravel state transitions?

You add guards and side effects to Laravel state transitions by defining them within your Transition classes. Guards evaluate whether a transition is allowed, while side effects execute additional logic during the transition process when calling transitionTo on your model.

Does Spatie Model States work with existing Laravel model validations?

Spatie Model States integrates with existing Laravel model validations by allowing you to define validation logic within transition classes. This ensures that state changes adhere to your application's business rules before the transition is executed.

What is the best way to structure a state hierarchy for a Laravel model?

The best way to structure a Laravel state hierarchy is to create an abstract base state class extending the Spatie Model States package, then define concrete state classes for each specific status. Transition classes handle the logic moving between these concrete states.