From eefd5fc5da58816af9050b00fb672edd31c448ec Mon Sep 17 00:00:00 2001 From: mirivlad Date: Fri, 27 Mar 2026 11:48:59 +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=D0=BA=D0=B0=D1=80=D1=82=D0=B8=D0=BD?= =?UTF-8?q?=D0=BE=D0=BA=20=D0=B2=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=B0?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Исправлена проверка hasText/hasImage в контроллере ✅ answer_text сохраняется как null если пустой ✅ Картинки отображаются в edit.blade.php в input-group-text ✅ Обновлены store и update методы Co-authored-by: Qwen-Coder --- .../Controllers/Admin/QuestionController.php | 18 ++++++++++++------ resources/views/admin/questions/edit.blade.php | 6 ++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Admin/QuestionController.php b/app/Http/Controllers/Admin/QuestionController.php index ba2a0e7..09a7b3a 100755 --- a/app/Http/Controllers/Admin/QuestionController.php +++ b/app/Http/Controllers/Admin/QuestionController.php @@ -80,13 +80,16 @@ class QuestionController extends Controller // Ответы для multiple_choice if ($validated['type'] === 'multiple_choice' && !empty($validated['answers'])) { foreach ($validated['answers'] as $answer) { - if (!empty($answer['text']) || !empty($answer['image'])) { + $hasText = !empty($answer['text']); + $hasImage = !empty($answer['image']); + + if ($hasText || $hasImage) { $imagePath = null; - if (!empty($answer['image'])) { + if ($hasImage) { $imagePath = $answer['image']->store('questions/answers', 'public'); } $question->answers()->create([ - 'answer_text' => $answer['text'], + 'answer_text' => $hasText ? $answer['text'] : null, 'image' => $imagePath, 'is_correct' => $answer['is_correct'] ?? false, 'sort_order' => $answer['sort_order'] ?? 0, @@ -187,13 +190,16 @@ class QuestionController extends Controller if ($validated['type'] === 'multiple_choice' && !empty($validated['answers'])) { $question->answers()->delete(); foreach ($validated['answers'] as $answer) { - if (!empty($answer['text']) || !empty($answer['image'])) { + $hasText = !empty($answer['text']); + $hasImage = !empty($answer['image']); + + if ($hasText || $hasImage) { $imagePath = null; - if (!empty($answer['image'])) { + if ($hasImage) { $imagePath = $answer['image']->store('questions/answers', 'public'); } $question->answers()->create([ - 'answer_text' => $answer['text'], + 'answer_text' => $hasText ? $answer['text'] : null, 'image' => $imagePath, 'is_correct' => $answer['is_correct'] ?? false, 'sort_order' => $answer['sort_order'] ?? 0, diff --git a/resources/views/admin/questions/edit.blade.php b/resources/views/admin/questions/edit.blade.php index b9fded7..05b1e90 100644 --- a/resources/views/admin/questions/edit.blade.php +++ b/resources/views/admin/questions/edit.blade.php @@ -40,10 +40,12 @@
@foreach($question->answers as $answer)
- + @if($answer->image) - Ответ +
+ Ответ +
@endif