Skip to content

Commit

Permalink
Add enum to array trait
Browse files Browse the repository at this point in the history
  • Loading branch information
relliv committed Aug 24, 2024
1 parent 0dea5a5 commit 0766aab
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/Traits/EnumToArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Traits;

trait EnumToArray
{

public static function names(): array
{
return array_column(self::cases(), 'name');
}

public static function values(): array
{
return array_column(self::cases(), 'value');
}

public static function array(): array
{
return array_combine(self::values(), self::names());
}
}

0 comments on commit 0766aab

Please sign in to comment.