feat(API): 문서 템플릿 기본필드 field_key $fillable 추가

- DocumentTemplateBasicField 모델에 field_key 필드 추가
- Mass Assignment 보호로 field_key 저장 누락 방지

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-11 15:58:37 +09:00
parent 8b78d62068
commit a3a4e18e8a
2 changed files with 73 additions and 0 deletions

View File

@@ -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',

View File

@@ -0,0 +1,71 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
// 1) field_key 컬럼 추가
Schema::table('document_template_basic_fields', function (Blueprint $table) {
$table->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');
});
}
};