From a1720818b5534f36eea3e421d9c4447c6557b3a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Thu, 5 Feb 2026 12:46:39 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EB=A9=94=EB=89=B4=20=EC=8B=B1=ED=81=AC=20?= =?UTF-8?q?=EC=9B=90=EA=B2=A9=20API=20=ED=98=B8=EC=B6=9C=20=EC=8B=9C=20?= =?UTF-8?q?=ED=85=8C=EB=84=8C=ED=8A=B8=20ID=20=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fetchRemoteMenus()에서 tenant_id 쿼리 파라미터 추가 - export() API에서 요청의 tenant_id 파라미터 우선 사용 - getMenuTreeForTenant() 메서드 추가로 특정 테넌트 메뉴 조회 지원 Co-Authored-By: Claude Opus 4.5 --- app/Http/Controllers/MenuSyncController.php | 25 ++++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/MenuSyncController.php b/app/Http/Controllers/MenuSyncController.php index 2cebb9a4..fcdbb680 100644 --- a/app/Http/Controllers/MenuSyncController.php +++ b/app/Http/Controllers/MenuSyncController.php @@ -127,8 +127,11 @@ public function export(Request $request): JsonResponse return response()->json(['error' => 'Unauthorized'], 401); } - $menus = $this->getMenuTree(); - $tenant = Tenant::find($this->getTenantId()); + // 요청에서 tenant_id를 받으면 사용, 없으면 세션 기반 + $tenantId = $request->query('tenant_id') ? (int) $request->query('tenant_id') : $this->getTenantId(); + + $menus = $this->getMenuTreeForTenant($tenantId); + $tenant = Tenant::find($tenantId); return response()->json([ 'success' => true, @@ -332,14 +335,22 @@ public function testConnection(Request $request): JsonResponse * 메뉴 트리 조회 */ private function getMenuTree(?int $parentId = null): array + { + return $this->getMenuTreeForTenant($this->getTenantId(), $parentId); + } + + /** + * 특정 테넌트의 메뉴 트리 조회 + */ + private function getMenuTreeForTenant(int $tenantId, ?int $parentId = null): array { $menus = Menu::withoutGlobalScopes() - ->where('tenant_id', $this->getTenantId()) + ->where('tenant_id', $tenantId) ->where('parent_id', $parentId) ->orderBy('sort_order') ->get(); - return $menus->map(function ($menu) { + return $menus->map(function ($menu) use ($tenantId) { return [ 'id' => $menu->id, 'name' => $menu->name, @@ -347,7 +358,7 @@ private function getMenuTree(?int $parentId = null): array 'icon' => $menu->icon, 'sort_order' => $menu->sort_order, 'options' => $menu->options, - 'children' => $this->getMenuTree($menu->id), + 'children' => $this->getMenuTreeForTenant($tenantId, $menu->id), ]; })->toArray(); } @@ -383,7 +394,9 @@ private function fetchRemoteMenus(array $env): array $response = Http::withHeaders([ 'X-Menu-Sync-Key' => $env['api_key'], 'Accept' => 'application/json', - ])->timeout(10)->get(rtrim($env['url'], '/') . '/menu-sync/export'); + ])->timeout(10)->get(rtrim($env['url'], '/') . '/menu-sync/export', [ + 'tenant_id' => $this->getTenantId(), // 현재 선택된 테넌트 전달 + ]); if (! $response->successful()) { throw new \Exception('API 오류: HTTP ' . $response->status());