Created
April 6, 2026 05:39
-
-
Save edgrosvenor/3f12340b65cbc0e70a4bec21f1585e54 to your computer and use it in GitHub Desktop.
Fat Enums: WithData attribute example - SubscriptionTier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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