Created
August 25, 2022 05:56
-
-
Save nepkto/590a26c531b2e2349025f7e3ec0b7417 to your computer and use it in GitHub Desktop.
Backed Enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Enums; | |
enum UserStatusEnum: string | |
{ | |
case ACTIVE = 'active'; | |
case INACTIVE = 'inactive'; | |
case BLOCKED = 'blocked'; | |
public static function lists(): array | |
{ | |
// Usefull in drop down | |
return array_combine( | |
array_column(self::cases(), 'name'), | |
array_column(self::cases(), 'value') | |
); | |
} | |
public static function values(): array | |
{ | |
return array_column(self::cases(), 'value'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment