Skip to content

Instantly share code, notes, and snippets.

@edgrosvenor
Created April 6, 2026 05:39
Show Gist options
  • Select an option

  • Save edgrosvenor/c00971fd454eebe6d36a73a145f2e12d to your computer and use it in GitHub Desktop.

Select an option

Save edgrosvenor/c00971fd454eebe6d36a73a145f2e12d to your computer and use it in GitHub Desktop.
Fat Enums: State machine definition with transition attributes
<?php
namespace App\Enums;
use ArtisanBuild\FatEnums\Attributes\CanTransitionTo;
use ArtisanBuild\FatEnums\Attributes\CanTransitionToSelf;
use ArtisanBuild\FatEnums\Attributes\FinalState;
use ArtisanBuild\FatEnums\Concerns\IsStateMachine;
use ArtisanBuild\FatEnums\Contracts\StateMachine;
enum OrderStatus: string implements StateMachine
{
use IsStateMachine;
public const DEFAULT = self::Pending;
#[CanTransitionTo([self::Processing, self::Cancelled])]
case Pending = 'pending';
#[CanTransitionTo([self::Shipped, self::Cancelled])]
#[CanTransitionToSelf] // Can re-process if needed
case Processing = 'processing';
#[CanTransitionTo([self::Delivered, self::Returned])]
case Shipped = 'shipped';
#[FinalState]
case Delivered = 'delivered';
#[FinalState]
case Cancelled = 'cancelled';
#[CanTransitionTo([self::Refunded])]
case Returned = 'returned';
#[FinalState]
case Refunded = 'refunded';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment