A simple and opinionated collection of PHP enum helpers inspired by https://github.com/archtechx/enums and https://github.com/BenSampo/laravel-enum. This package is framework agnostic, but if you use Laravel consider using this linked package https://github.com/datomatic/laravel-enum-helper and https://github.com/datomatic/laravel-enum-collections.

Construct enum by name or value: from(), tryFrom(), fromName(), tryFromName(), fromValue(), tryFromValue() methods

In all examples we'll use the classes described below: use Datomatic\EnumHelper\EnumHelper; // Pure enum enum PureEnum { use EnumHelper; case ACCEPTED; case DISCARDED; } enum PascalCasePureEnum { use EnumHelper; case Pending; case Accepted; case Discarded; case NoResponse; } // BackedEnum enum StringBackedEnum: string { use EnumHelper; case ACCEPTED = 'A'; case DISCARDED = 'D'; } enum IntBackedEnum: int { use EnumHelper; case ACCEPTED = case DISCARDED = case NO_RESPONSE = }
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners