From d1d7eecb69c9b9ad9355ea2e6bda5aac9cd68977 Mon Sep 17 00:00:00 2001 From: mirivlad Date: Fri, 27 Mar 2026 16:33:14 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=D0=A1=D0=BE=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D1=83=D1=89=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D1=83=D1=8E=D1=89=D0=B8=D1=85=20=D0=BA=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=BA=20=D0=BF=D1=80=D0=B8=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ edit.blade.php передаёт existing_image ✅ update() сохраняет existing_image если новый файл не загружен ✅ update() удаляет старую картинку если загружена новая Co-authored-by: Qwen-Coder --- .../Controllers/Admin/QuestionController.php | 19 +++++++++++++++---- .../views/admin/questions/edit.blade.php | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Admin/QuestionController.php b/app/Http/Controllers/Admin/QuestionController.php index 9b38855..6a5946d 100755 --- a/app/Http/Controllers/Admin/QuestionController.php +++ b/app/Http/Controllers/Admin/QuestionController.php @@ -237,11 +237,22 @@ class QuestionController extends Controller $hasImage = $request->hasFile("answers.$index.image"); $isCorrect = isset($answer['is_correct']) && $answer['is_correct'] === '1'; - if ($hasText || $hasImage) { - $imagePath = null; - if ($hasImage) { - $imagePath = $request->file("answers.$index.image")->store('questions/answers', 'public'); + // Получаем существующую картинку если новая не загружена + $existingImagePath = $answer['existing_image'] ?? null; + $imagePath = null; + + if ($hasImage) { + // Удаляем старую если есть + if ($existingImagePath) { + \Storage::disk('public')->delete($existingImagePath); } + $imagePath = $request->file("answers.$index.image")->store('questions/answers', 'public'); + } else { + // Оставляем существующую + $imagePath = $existingImagePath; + } + + if ($hasText || $imagePath) { $question->answers()->create([ 'answer_text' => $hasText ? $answer['text'] : null, 'image' => $imagePath, diff --git a/resources/views/admin/questions/edit.blade.php b/resources/views/admin/questions/edit.blade.php index db908a7..9a7950a 100644 --- a/resources/views/admin/questions/edit.blade.php +++ b/resources/views/admin/questions/edit.blade.php @@ -41,6 +41,7 @@ @foreach($question->answers as $answer)
+ @if($answer->image)