diff --git a/app/Services/ItemMaster/ItemPageService.php b/app/Services/ItemMaster/ItemPageService.php index 3bc51e9..db9ed7f 100644 --- a/app/Services/ItemMaster/ItemPageService.php +++ b/app/Services/ItemMaster/ItemPageService.php @@ -43,11 +43,16 @@ public function store(array $data): ItemPage { $tenantId = $this->tenantId(); $userId = $this->apiUserId(); + $itemType = strtoupper($data['item_type']); + + // item_type으로 common_codes에서 source_table 조회 + $sourceTable = $this->getSourceTableFromCommonCode($itemType); $page = ItemPage::create([ 'tenant_id' => $tenantId, 'page_name' => $data['page_name'], - 'item_type' => $data['item_type'], + 'item_type' => $itemType, + 'source_table' => $sourceTable, 'absolute_path' => $data['absolute_path'] ?? null, 'is_active' => true, 'created_by' => $userId, @@ -127,4 +132,23 @@ public function destroy(int $id): void $page->update(['deleted_by' => $userId]); $page->delete(); } + + /** + * item_type에 해당하는 source_table을 common_codes.attributes에서 조회 + */ + private function getSourceTableFromCommonCode(string $itemType): ?string + { + $commonCode = \DB::table('common_codes') + ->where('code_group', 'item_type') + ->where('code', strtoupper($itemType)) + ->first(); + + if (! $commonCode || ! $commonCode->attributes) { + return null; + } + + $attrs = json_decode($commonCode->attributes, true); + + return $attrs['source_table'] ?? null; + } }