Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dha1095's avatar

I get always radio button value is "on" in Livewire

if (!empty($this->quiz_questions) && !empty($this->quiz_answers) && $this->activeTab == 2) {
            $quiz_questions_answers_rules = [
                'question_category' => 'required',
                'question_points' => 'required|numeric',
                'question_text' => 'required',
                'question_type' => 'required',
                'quiz_answers.*.answer_type' => 'required',
                'quiz_answers.*.answer_info' => 'required_if:quiz_answers.*.answer_type,Text',
                'quiz_answers.*.answer_image' => 'required_if:quiz_answers.*.answer_type,Image|image|max:4096',
                'quiz_answers.*.answer_code_language' => 'required_if:quiz_answers.*.answer_type,Code Snippet',
                'quiz_answers.*.is_correct' => 'nullable'
            ];

            $quiz_questions_answers_messages = [
                'question_category.required' => 'Please select the question category.',
                'question_points.required' => 'The question points are required.',
                'question_points.numeric' => 'The question points must be a number.',
                'question_text.required' => 'The question is required.',
                'question_type.required' => 'Please select the question type.',
                'quiz_answers.*.answer_type.required' => 'Each answer must have a type.',
                'quiz_answers.*.answer_info.required_if' => 'Please enter the answer information for text answers.',
                'quiz_answers.*.answer_image.required_if' => 'Please upload an image for the answer.',
                'quiz_answers.*.answer_image.image' => 'The answer file must be an image.',
                'quiz_answers.*.answer_image.max' => 'The answer image must not be larger than 4MB.',
                'quiz_answers.*.answer_code_language.required_if' => 'Please select a programming language for the code snippet answer.',
            ];

            // Additional conditional rules
            if ($this->question_type == 'Text') {
                $quiz_questions_answers_rules['question_info'] = 'required';
                $quiz_questions_answers_messages['question_info.required'] = 'Please enter the question information.';
            } elseif ($this->question_type == 'Image') {
                $quiz_questions_answers_rules['question_image'] = 'required|image|max:4096';
                $quiz_questions_answers_messages['question_image.required'] = 'Please upload an image for the question.';
                $quiz_questions_answers_messages['question_image.image'] = 'The file must be an image.';
                $quiz_questions_answers_messages['question_image.max'] = 'The image must not be larger than 4MB.';
            } elseif ($this->question_type == 'Code Snippet') {
                $quiz_questions_answers_rules['code_language'] = 'required';
                $quiz_questions_answers_messages['code_language.required'] = 'Please select a programming language.';
            }

            $validated['quiz_questions_answers'] = $this->validate($quiz_questions_answers_rules, $quiz_questions_answers_messages);
            dd($validated);
        }
<div class="col-3">
            <div class="mt-4 pt-3">
                <div class="form-check">
                    @php
                        $model = 'quiz_answers.' . $key . '.is_correct';
                    @endphp
                    <input class="form-check-input" type="radio" id="{{ $model }}" name="is_correct"
                        wire:model.live="{{ $model }}">
                    <label class="form-check-label" for="{{ $model }}">Correct Answer</label>
                </div>
            </div>
        </div>
0 likes
1 reply
dha1095's avatar
array:2 [▼ // app/Livewire/Quizs/QuizAdd.php:194
  "quiz_details" => array:8 [▶]
  "quiz_questions_answers" => array:5 [▼
    "question_category" => "Multiple Choice"
    "question_points" => "95"
    "question_text" => "<p>Animi, est assumenda.</p>"
    "question_type" => "Select"
    "quiz_answers" => array:2 [▼
      0 => array:3 [▼
        "answer_type" => "Text"
        "answer_info" => "Aut qui nisi nostrud"
        "is_correct" => "on"
      ]
      1 => array:3 [▼
        "answer_type" => "Text"
        "answer_info" => "hghgfh"
        "is_correct" => "on"
      ]
    ]
  ]
]

Please or to participate in this conversation.