Skip to content

Instantly share code, notes, and snippets.

@nepkto
Created August 25, 2022 05:56
Show Gist options
  • Save nepkto/590a26c531b2e2349025f7e3ec0b7417 to your computer and use it in GitHub Desktop.
Save nepkto/590a26c531b2e2349025f7e3ec0b7417 to your computer and use it in GitHub Desktop.
Backed Enum
<?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