Files
alrahma_sunday_school_api/app/Services/Roles/RoleSwitchService.php
T
2026-03-10 17:11:48 -04:00

26 lines
637 B
PHP

<?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]);
}
}