feat: add UserLevel enum and integrate it in User Modal, UserResource and UserFactory
This commit is contained in:
67
app/enum/UserLevel.php
Normal file
67
app/enum/UserLevel.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\enum;
|
||||
|
||||
enum UserLevel: int
|
||||
{
|
||||
case SUPERADMIN = 9;
|
||||
case NORMALUSER = 0;
|
||||
case BANNEDUSER = 1;
|
||||
|
||||
/**
|
||||
* Get the user-friendly label for the enum value.
|
||||
*/
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::SUPERADMIN => 'Super Admin',
|
||||
self::NORMALUSER => 'Normal User',
|
||||
self::BANNEDUSER => 'Banned User',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color for the enum value (for UI display).
|
||||
*/
|
||||
public function getColor(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::SUPERADMIN => 'danger', // Red for highest privilege
|
||||
self::NORMALUSER => 'success', // Green for regular users
|
||||
self::BANNEDUSER => 'warning', // Yellow/Orange for banned users
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon for the enum value.
|
||||
*/
|
||||
public function getIcon(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::SUPERADMIN => 'heroicon-o-shield-check',
|
||||
self::NORMALUSER => 'heroicon-o-user',
|
||||
self::BANNEDUSER => 'heroicon-o-no-symbol',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all options as array for select fields.
|
||||
*/
|
||||
public static function getSelectOptions(): array
|
||||
{
|
||||
return collect(self::cases())->mapWithKeys(fn ($case) => [
|
||||
$case->value => $case->getLabel(),
|
||||
])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the badge configuration for Filament.
|
||||
*/
|
||||
public function getBadge(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->getLabel(),
|
||||
'color' => $this->getColor(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user