I want to retrieve the data that stores the total questions on a quiz, but when I loop using the result of the total question data that I got using the query below, the result shows Object of class Illuminate \ Support \ Collection could not be converted to int. does anyone know how to solve it?
Here is my code
public function insertStdAnswer(Request $request,$id){
$_num = DB::table('quiz')
->select('question_total')
->where('id', $id)
->get();
for($i = 0; $i <= $_num ; $i++){
$quiz_id = $id;
$user_id_std_quiz = Auth::id();
$std_answer = $request->input('answer-'.$i);
$nomor_quiz = $request->input('soal-'.$i);
DB::insert('insert into studentquiz (`std_quiz_id`,`user_id_std_quiz`,`std_answer`,`nomor_quiz`) values(?,?,?,?)',
[$quiz_id,$user_id_std_quiz,$std_answer, $nomor_quiz]);
}
Aucun commentaire:
Enregistrer un commentaire