Skip to content

Commit 6df942a

Browse files
committed
Add enum to array trait
1 parent 0684cc5 commit 6df942a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

app/Traits/EnumToArray.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Traits;
4+
5+
trait EnumToArray
6+
{
7+
8+
public static function names(): array
9+
{
10+
return array_column(self::cases(), 'name');
11+
}
12+
13+
public static function values(): array
14+
{
15+
return array_column(self::cases(), 'value');
16+
}
17+
18+
public static function array(): array
19+
{
20+
return array_combine(self::values(), self::names());
21+
}
22+
}

0 commit comments

Comments
 (0)