add role permission logic

This commit is contained in:
root
2026-03-10 17:11:48 -04:00
parent abebe0d9c0
commit c235fd2170
40 changed files with 1896 additions and 838 deletions
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App\Services\Roles;
use App\Models\UserRole;
use Illuminate\Support\Facades\Session;
class RoleSwitchService
{
public function __construct(private RoleDashboardService $dashboardService)
{
}
public function getUserRoleNames(int $userId): array
{
$roles = UserRole::getRolesByUserId($userId);
return array_values(array_filter(array_map(fn ($r) => (string) ($r['role_name'] ?? ''), $roles)));
}
public function switchRole(string $role): string
{
Session::put('active_role', $role);
return $this->dashboardService->bestDashboardRouteFor([$role]);
}
}