In my case, I have to fetch Questions one by one with their respective options and save the option id into answers table, I can able fetch questions one by one but not able to save option id's into answers table.
Here is my controller
public function getQuestion(Request $request,$qId)
{
$questions = Question::find($qId);
$options = Question::find($qId)->options;
$previous = Question::where('id', '<', $questions->id)->max('id');
$next = Question::where('id', '>', $questions->id)->min('id');
return view('Pages/User/Questions/Question2')
->with('options',$options)
->with('questions',$questions)
->with('previous',Question::find($previous))
->with('next',Question::find($next));
}
My Route
Route::get('/question/{qId}', [
'uses' => 'customers\QuestionController@getQuestion',
'as' => 'question'
]);
My view
@foreach
<h3></h3>
@foreach($options as $option)
<div class="checkbox">
<label><input type="checkbox" name="option"></label>
@endforeach
@endforeach
@if($previous)
<a href="">Previous</a>
@endif
@if($next)
<a href="" >Next</a>
@endif
That is how code looks like I can fecth records row by row not but able to save option id in answers table because of its not there in form.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire