feat: [bending] 수정 시 code 변경 허용 + 중복 코드 검사 (422 반환)
This commit is contained in:
@@ -83,7 +83,25 @@ public function update(int $id, array $data): BendingItem
|
||||
{
|
||||
$item = BendingItem::findOrFail($id);
|
||||
|
||||
// code는 수정 불가 (고유 품목코드)
|
||||
// code 변경 시 중복 검사
|
||||
if (array_key_exists('code', $data) && $data['code'] && $data['code'] !== $item->code) {
|
||||
$exists = BendingItem::withoutGlobalScopes()
|
||||
->where('code', $data['code'])
|
||||
->where('id', '!=', $id)
|
||||
->exists();
|
||||
if ($exists) {
|
||||
throw new \Illuminate\Validation\ValidationException(
|
||||
validator([], []),
|
||||
response()->json([
|
||||
'success' => false,
|
||||
'message' => "코드 '{$data['code']}'가 이미 존재합니다.",
|
||||
'errors' => ['code' => ["코드 '{$data['code']}'는 이미 사용 중입니다. 다른 코드를 입력하세요."]],
|
||||
], 422)
|
||||
);
|
||||
}
|
||||
$item->code = $data['code'];
|
||||
}
|
||||
|
||||
$columns = [
|
||||
'item_name', 'item_sep', 'item_bending',
|
||||
'material', 'item_spec', 'model_name', 'model_UA',
|
||||
|
||||
Reference in New Issue
Block a user