radfusion/app/Services/ACL/RoleService.php
2025-01-29 14:53:59 +06:00

29 lines
653 B
PHP

<?php
namespace App\Services\ACL;
use App\Domain\ACL\Role;
use Spatie\Permission\Models\Role as SpatieRole;
final class RoleService
{
private static array $roles = [];
private static function initCache(): void
{
if (empty(self::$roles)) {
self::$roles = SpatieRole::pluck('id', 'name')->toArray();
}
}
public static function select(): array
{
// self::initCache();
return collect(Role::cases())
// ->mapWithKeys(fn (Role $r) => [self::$roles[$r->value] => $r->name])
->mapWithKeys(fn (Role $r) => [$r->value => $r->name])
->toArray();
}
}