henzeb/enumhancer

View on GitHub
docs/labels.md

Summary

Maintainability
Test Coverage
# Labels

Just like [Spatie's PHP Enum](https://github.com/spatie/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

```php
use Henzeb\Enumhancer\Concerns\Labels;

enum YourEnum {
    use Labels;

    case ENUM;
    case NO_LABEL;

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

### Examples

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