diff --git a/src/Traits/LazyEnum.php b/src/Traits/LazyEnum.php index ec34e62..dac765a 100644 --- a/src/Traits/LazyEnum.php +++ b/src/Traits/LazyEnum.php @@ -69,6 +69,21 @@ public static function toValues(): array return $array; } + public static function toLabels(): array + { + $array = []; + + foreach (static::cases() as $definition) { + if (method_exists($definition, 'getLabel')) { + $array[$definition->name] = $definition->getLabel(); + } else { + $array[$definition->name] = $definition->name; + } + } + + return $array; + } + public function getLabel(): ?string { return $this->name;