From a3a4e18e8ae45a5f0d771b234f13f9a7d5c74a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Wed, 11 Feb 2026 15:58:37 +0900 Subject: [PATCH] =?UTF-8?q?feat(API):=20=EB=AC=B8=EC=84=9C=20=ED=85=9C?= =?UTF-8?q?=ED=94=8C=EB=A6=BF=20=EA=B8=B0=EB=B3=B8=ED=95=84=EB=93=9C=20fie?= =?UTF-8?q?ld=5Fkey=20$fillable=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DocumentTemplateBasicField 모델에 field_key 필드 추가 - Mass Assignment 보호로 field_key 저장 누락 방지 Co-Authored-By: Claude Opus 4.6 --- .../Documents/DocumentTemplateBasicField.php | 2 + ..._key_to_document_template_basic_fields.php | 71 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 database/migrations/2026_02_11_100001_add_field_key_to_document_template_basic_fields.php diff --git a/app/Models/Documents/DocumentTemplateBasicField.php b/app/Models/Documents/DocumentTemplateBasicField.php index c2e22c6..038298d 100644 --- a/app/Models/Documents/DocumentTemplateBasicField.php +++ b/app/Models/Documents/DocumentTemplateBasicField.php @@ -12,6 +12,7 @@ * @property int $template_id * @property string $label 필드 라벨 * @property string $field_type 필드 타입 (text/date/select 등) + * @property string|null $field_key common_codes(doc_template_basic_field) 참조 키 * @property string|null $default_value 기본값 * @property int $sort_order 정렬 순서 */ @@ -22,6 +23,7 @@ class DocumentTemplateBasicField extends Model protected $fillable = [ 'template_id', 'label', + 'field_key', 'field_type', 'default_value', 'sort_order', diff --git a/database/migrations/2026_02_11_100001_add_field_key_to_document_template_basic_fields.php b/database/migrations/2026_02_11_100001_add_field_key_to_document_template_basic_fields.php new file mode 100644 index 0000000..e755dec --- /dev/null +++ b/database/migrations/2026_02_11_100001_add_field_key_to_document_template_basic_fields.php @@ -0,0 +1,71 @@ +string('field_key', 30)->nullable()->after('label') + ->comment('common_codes(doc_template_basic_field) 참조 키'); + }); + + // 2) common_codes에 doc_template_basic_field 코드그룹 시드 + $codes = [ + ['code' => 'product_name', 'name' => '품명', 'attributes' => json_encode(['data_path' => 'productName']), 'sort_order' => 1], + ['code' => 'specification', 'name' => '규격', 'attributes' => json_encode(['data_path' => 'specification']), 'sort_order' => 2], + ['code' => 'lot_no', 'name' => 'LOT NO', 'attributes' => json_encode(['data_path' => 'lotNo']), 'sort_order' => 3], + ['code' => 'lot_size', 'name' => '로트크기', 'attributes' => json_encode(['data_path' => 'lotSize']), 'sort_order' => 4], + ['code' => 'client', 'name' => '발주처/수주처', 'attributes' => json_encode(['data_path' => 'client']), 'sort_order' => 5], + ['code' => 'site_name', 'name' => '현장명', 'attributes' => json_encode(['data_path' => 'projectName']), 'sort_order' => 6], + ['code' => 'inspection_date', 'name' => '검사일자', 'attributes' => json_encode(['data_path' => '_inspection_date']), 'sort_order' => 7], + ['code' => 'inspector', 'name' => '검사자', 'attributes' => json_encode(['data_path' => '_inspector']), 'sort_order' => 8], + ]; + + $now = now(); + foreach ($codes as $code) { + DB::table('common_codes')->insert(array_merge($code, [ + 'tenant_id' => 1, + 'code_group' => 'doc_template_basic_field', + 'is_active' => true, + 'created_at' => $now, + 'updated_at' => $now, + ])); + } + + // 3) 기존 template 59 basic_fields에 field_key 매핑 + $labelKeyMap = [ + '품명' => 'product_name', + '규격' => 'specification', + '수주 LOT NO' => 'lot_no', + '로트크기' => 'lot_size', + '발주처' => 'client', + '현장명' => 'site_name', + '검사일자' => 'inspection_date', + '검사자' => 'inspector', + ]; + + foreach ($labelKeyMap as $label => $fieldKey) { + DB::table('document_template_basic_fields') + ->where('template_id', 59) + ->where('label', $label) + ->update(['field_key' => $fieldKey]); + } + } + + public function down(): void + { + DB::table('common_codes') + ->where('code_group', 'doc_template_basic_field') + ->delete(); + + Schema::table('document_template_basic_fields', function (Blueprint $table) { + $table->dropColumn('field_key'); + }); + } +};