why not have one input field for the correct answer, and other fields for the dummy answers?
You can always randomise the order of the answers when you get them for display
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Select correct answer when creating quiz questions.
I am creating a multiple choice question for a quiz and looking for a way to indicate the correct answer at the same time the question options (answer) are created.
This is easy enough if you use a checkbox because you can just send through an additional is_correct field, however the risk of multiple correct answers being checked is high. Ideally I want to use a radio button but the name attribute needs to be the same and I can not figure ot how to indicate the correct answer in the database.
Controller The question options (answers) are throught the question with the saveMany() method.
<!-- Create question -->
$q = question->create('questions');
<!-- Create many answers (related to question) -->
$q->answers->createMany('answers');
Template
<!-- Create question_options array with checkbox -->
<!-- works but will be possible to check multiple answers -->
<input name="question_options[][answer]" type="text">
<input type="checkbox" name="question_options[0][is_correct]">
<input name="question_options[][answer]" type="text">
<input type="checkbox" name="question_options[1][is_correct]">
or
<!-- Create question_options array with radio -->
<!-- Ideal for single selection but can not get correct when persisting -->
<input name="question_options[][answer]" type="text">
<input type="checkbox" name="answer_id">
<input name="question_options[][answer]" type="text">
<input type="checkbox" name="answer_id">
Please or to participate in this conversation.