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