# [API] 절곡품 resolve-item 500 에러 수정 (specification 컬럼) **날짜:** 2026-03-18 **작성자:** Claude Code **대상:** sam-api (PHP Laravel) **심각도:** High **영향 범위:** 절곡품 재고생산 등록 > 품목 매핑 조회 --- ## 1. 증상 절곡품 재고생산 등록 화면에서 품목명 + 종류 + 모양&길이 3개 드롭다운 선택 시 **500 Internal Server Error** 발생. ``` SQLSTATE[42S22]: Column not found: 1054 Unknown column 'specification' in 'field list' SQL: select `id`, `code`, `name`, `specification`, `unit` from `items` where ... ``` --- ## 2. 원인 `BendingCodeService::resolveItem()` 메서드에서 Eloquent eager loading에 `specification`을 DB 컬럼으로 직접 지정하고 있었으나, `items` 테이블에는 `specification` 컬럼이 존재하지 않음. `specification`은 **Item 모델의 accessor** (`$appends`)로, `attributes` JSON 컬럼에서 `spec` 또는 `specification` 값을 추출하는 가상 속성. ```php // Item 모델 protected $appends = ['specification']; public function getSpecificationAttribute(): ?string { $attrs = $this->attributes['attributes'] ?? null; // ... return $attrs['spec'] ?? $attrs['specification'] ?? null; } ``` --- ## 3. 수정 내용 **파일:** `app/Services/BendingCodeService.php:139` ```php // 변경 전 (500 에러) ->with('item:id,code,name,specification,unit') // 변경 후 (정상) ->with('item:id,code,name,attributes,unit') ``` `specification` 대신 실제 DB 컬럼 `attributes`를 select하면, accessor가 자동으로 `specification` 값을 계산하여 반환함. --- ## 4. 검증 - 매핑된 조합 선택 시: 200 응답 + `item_code`, `item_name`, `specification`, `expected_code` 정상 반환 - 매핑 안 된 조합 선택 시: 404 응답 + `expected_code` 정상 반환 (500 에러 해소) --- ## 5. 관련 변경 | 항목 | 설명 | |------|------| | 동일 커밋 | `expected_code` 필드 추가 (BendingController.php) | | 프론트엔드 | BendingLotForm.tsx에서 `expected_code` 표시 로직 적용 완료 |