feat: [bending] 수정 시 코드 편집 가능 + API 중복 에러 메시지 표시

This commit is contained in:
김보곤
2026-03-21 11:29:58 +09:00
parent 2cd0fd554c
commit 4410af04cc
2 changed files with 14 additions and 3 deletions

View File

@@ -168,6 +168,7 @@ public function store(Request $request)
public function update(Request $request, int $id)
{
$validated = $request->validate([
'code' => 'required|string|max:20',
'name' => 'required|string|max:200',
'item_sep' => 'required|in:스크린,철재',
'item_bending' => 'required|string|max:50',
@@ -188,7 +189,13 @@ public function update(Request $request, int $id)
$response = $this->api()->put("/api/v1/bending-items/{$id}", $data);
if (! $response->successful()) {
return back()->withErrors(['api' => $response->json('message', 'API 오류')])->withInput();
$body = $response->json();
$errorBag = ['api' => $body['message'] ?? 'API 오류'];
foreach ($body['errors'] ?? [] as $field => $msgs) {
$errorBag[$field] = is_array($msgs) ? implode(', ', $msgs) : $msgs;
}
return back()->withErrors($errorBag)->withInput();
}
$this->handleImageUpload($request, $id);