Aplikasi Keuangan yang mengatur lalu lintas transaksi antara bank dan aplikasi internal Kampus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 lines
1022 B

<?php
namespace App\UI\Enums\Concerns;
use BackedEnum;
use Illuminate\Support\Str;
/**
* Label interaction utilities for Enums.
* This trait will provide methods for interacting with labels.
* The label() method returns the translated label for the Enum value.
* The key is from domains/<domains>/enum.enum-slugs.<value>
*
* @mixin BackedEnum
*/
trait InteractsWithLabels
{
public function label(): string
{
$fqcn = static::class;
$domain = Str::between($fqcn, 'App\\Domains\\', '\\Enums\\');
$domainSlug = Str::kebab($domain);
$className = Str::afterLast($fqcn, '\\');
$enumSlug = Str::kebab($className);
$translationKey = "domains/{$domainSlug}/enum.{$enumSlug}.{$this->value}";
return __($translationKey);
}
public static function options(): array
{
$mappedArray = array_map(fn(self $self) => [
$self->value => $self->label(),
], self::cases());
return array_merge(...$mappedArray);
}
}