Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save edgrosvenor/3f12340b65cbc0e70a4bec21f1585e54 to your computer and use it in GitHub Desktop.
Fat Enums: WithData attribute example - SubscriptionTier
<?php
namespace App\Enums;
use ArtisanBuild\FatEnums\Attributes\WithData;
use ArtisanBuild\FatEnums\Concerns\HasKeyValueAttributes;
enum SubscriptionTier: string
{
use HasKeyValueAttributes;
#[WithData([
'label' => 'Free Forever',
'price' => 0,
'max_projects' => 3,
'max_team_members' => 1,
])]
case Free = 'free';
#[WithData([
'label' => 'Professional',
'price' => 29,
'max_projects' => 25,
'max_team_members' => 5,
])]
case Pro = 'pro';
#[WithData([
'label' => 'Enterprise',
'price' => 99,
'max_projects' => -1, // unlimited
'max_team_members' => -1,
])]
case Enterprise = 'enterprise';
}
// Usage:
$tier = SubscriptionTier::Pro;
$tier->data('label'); // "Professional"
$tier->data('price'); // 29
$tier->data('max_projects'); // 25
$tier->data(); // ['label' => 'Professional', 'price' => 29, ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment