Level 80
@smartnathan What specifically is your question? If you want to get the option that’s the answer, just do a where condition:
$answer = $question->options()->where('is_answer', true)->first();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Good morning, I am creating a simple quiz application where a user can add multiple choice questions and Select the right answer. I want to be able to get the correct answer and the associated option value. Please, how do I go about this. Or what is the best way to get this done. Thank you, I do appreciate.
<div class="row">
<div class="col-sm-12">
<div class="input-group fg-float">
<span class="input-group-addon"><i class="zmdi zmdi-pin-help
"></i></span>
<div class="fg-line">
<input name="question" type="text" class="form-control">
<label class="fg-label">Question</label>
</div>
</div>
</div>
</div>
<br /><br />
<div class="row">
<div class="col-sm-6">
<div class="input-group fg-float">
<span class="input-group-addon"><i class="zmdi zmdi-check-circle"></i></span>
<div class="fg-line">
<input name="name[]" type="text" class="form-control">
<label class="fg-label">Optiion</label>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="radio m-b-15">
<label>
<input name="answer[]" type="radio" value="1">
<i class="input-helper"></i>
Option one is this and that-be sure to include why it's great
</label>
</div>
</div>
</div>
<br /><br />
<div class="row">
<div class="col-sm-6">
<div class="input-group fg-float">
<span class="input-group-addon"><i class="zmdi zmdi-check-circle"></i></span>
<div class="fg-line">
<input name="name[]" type="text" class="form-control">
<label class="fg-label">Optiion</label>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="radio m-b-15">
<label>
<input name="answer[]" type="radio" value="1">
<i class="input-helper"></i>
Option one is this and that-be sure to include why it's great
</label>
</div>
</div>
</div>
<br /><br />
<div class="row">
<div class="col-sm-6">
<div class="input-group fg-float">
<span class="input-group-addon"><i class="zmdi zmdi-check-circle"></i></span>
<div class="fg-line">
<input name="name[]" type="text" class="form-control">
<label class="fg-label">Optiion</label>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="radio m-b-15">
<label>
<input name="answer[]" type="radio" value="1">
<i class="input-helper"></i>
Option one is this and that-be sure to include why it's great
</label>
</div>
</div>
</div>
<br /><br />
<div class="row">
<div class="col-sm-6">
<div class="input-group fg-float">
<span class="input-group-addon"><i class="zmdi zmdi-check-circle"></i></span>
<div class="fg-line">
<input name="name[]" type="text" class="form-control">
<label class="fg-label">Optiion</label>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="radio m-b-15">
<label>
<input name="answer[]" type="radio" value="1">
<i class="input-helper"></i>
Option one is this and that-be sure to include why it's great
</label>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Add Question</button>
Schema::create('quiz_options', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->softDeletes();
$table->integer('quiz_question_id')->nullable();
$table->string('name')->nullable();
$table->boolean('is_answer')->nullable();
$table->string('answer')->nullable();
});
Schema::create('quiz_questions', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->softDeletes();
$table->integer('quiz_type_id')->nullable();
$table->string('question')->nullable();
$table->boolean('is_active')->nullable();
});
Please or to participate in this conversation.