在我的情況下,我必須使用它們各自的選項逐個提取問題,並將選項ID保存到答案表中,我可以一個一個提取問題,但不能將選項ID保存到答案表中。如何逐行讀取記錄並保存其值
這裏是我的控制器
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));
}
我的路線
Route::get('/question/{qId}', [
'uses' => 'customers\[email protected]',
'as' => 'question'
]);
我的觀點
@foreach
<h3>{{$questions->question_name}}</h3>
@foreach($options as $option)
<div class="checkbox">
<label><input type="checkbox" name="option">{{$option->option}}</label>
@endforeach
@endforeach
@if($previous)
<a href="{{route('question',['qId' => $previous->id])}}">Previous</a>
@endif
@if($next)
<a href="{{route('question',['qId' => $next->id])}}" >Next</a>
@endif
即代碼看起來像我可以按行不能不能夠fecth記錄行將選項ID保存在答案表中,因爲它沒有在表單中。
那麼爲什麼你不使用窗體? –
@ Mohammad b我嘗試過形式,但無法一個一個地抓取記錄。請您幫忙解決。 –
解釋你如何在數據庫中存儲答案? –