feat(trait): add WithComment and Withvalue for enum utils
This commit is contained in:
parent
bcc442a00b
commit
c9e012e387
11
app/Traits/Enum/WithComment.php
Normal file
11
app/Traits/Enum/WithComment.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits\Enum;
|
||||
|
||||
trait WithComment
|
||||
{
|
||||
public static function comment(): string
|
||||
{
|
||||
return implode(', ', array_map(fn ($case) => "{$case->value}: {$case->label()}", self::cases()));
|
||||
}
|
||||
}
|
||||
11
app/Traits/Enum/WithValue.php
Normal file
11
app/Traits/Enum/WithValue.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits\Enum;
|
||||
|
||||
trait WithValue
|
||||
{
|
||||
public static function values(): array
|
||||
{
|
||||
return array_map(fn ($case) => $case->value, self::cases());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user