feat(trait): menambahkan WithCommentEnum dan WithValueEnum
This commit is contained in:
parent
6317037796
commit
8211f819b0
11
app/Traits/WithCommentEnum.php
Normal file
11
app/Traits/WithCommentEnum.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait WithCommentEnum
|
||||
{
|
||||
public static function comment(): string
|
||||
{
|
||||
return implode(', ', array_map(fn ($case) => "{$case->value}: {$case->label()}", self::cases()));
|
||||
}
|
||||
}
|
||||
11
app/Traits/WithValueEnum.php
Normal file
11
app/Traits/WithValueEnum.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait WithValueEnum
|
||||
{
|
||||
public static function values(): array
|
||||
{
|
||||
return array_map(fn ($case) => $case->value, self::cases());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user