id() ?? 0); if ($userId <= 0) { return $this->error('Please log in first.', Response::HTTP_UNAUTHORIZED); } $roles = $this->switchService->getUserRoleNames($userId); if (empty($roles)) { return $this->error('No roles assigned to this user.', Response::HTTP_NOT_FOUND); } return $this->success([ 'roles' => $roles, ]); } public function switch(RoleSwitchRequest $request): JsonResponse { $role = (string) $request->validated()['role']; $route = $this->switchService->switchRole($role); return $this->success([ 'role' => $role, 'dashboard_route' => $route, ], 'Role switched successfully.'); } }