Laravel Backed Enums is an awesome package that supercharges your PHP8-backed enums with superpowers like localization support and fluent comparison methods. The enum you create must implement the BackedEnum interface and also use the IsBackedEnum trait. The interface is required for Laravel to cast your enum correctly and the trait is what gives your enum its superpowers. use Webfox\LaravelBackedEnums\BackedEnum; use Webfox\LaravelBackedEnums\IsBackedEnum; enum VolumeUnitEnum: string implements BackedEnum { use IsBackedEnum; case GRAMS = "GRAMS"; case KILOGRAMS = "KILOGRAMS"; }
If you do not specify a label in the lang file these methods will return the value assigned to the enum inside the enum file.