Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 644 Bytes

labels.md

File metadata and controls

33 lines (25 loc) · 644 Bytes

Labels

Just like Spatie's PHP Enum, you can add labels to your enums. This is largely backwards compatible with their package, except that it also works for basic enums in which case it returns the name if not specified.

Usage

use Henzeb\Enumhancer\Concerns\Labels;

enum YourEnum {
    use Labels;

    case ENUM;
    case NO_LABEL;

    public static function labels(): array
    {
        return [
            'ENUM' => 'Your label';
        ];
    }
}

Examples

YourEnum::ENUM->label(); // will return 'Your label'
YourEnum::NO_LABEL->label(); // will return 'NO_LABEL';