hello,
i have a quiz App project, now iam done with all issues from the dashboard
now coming to the point where the student will make the exam
so now i have some issues
1 - i need to choose random 30 question out of my database
2 - i need to pass all of them with there answers and the correct answer to a java script
as in my js i have this
var quiz = [
{
"question" : "my question from my db like ( $question->question) ",
"image" : "path/to/image ( $question->image) ",
"choices" : [
"( $question->answers[0]) ",
"( $question->answers[1])",
"( $question->answers[2])",
],
"correct" : "( still didnt implement a method in my Question model to get the correct answer as my correct answer is a Boolean field in the answers table )",
},
etc... to the next question
];
i try to use laracasts utilities but i didnt know how to pass all of these object
is there way to do it with js or it will be better if its passed to Vuejs =( ?
any suggestion or some example or some idea to implement this
thank you
edit for the correct method i implement it in this way
public function correctAnswer()
{
$answer = $this->answers()->whereCorrect(1)->first();
return $answer->answer;
}
so the call will be like this
'correct' => $question->correctAnswer()
to get the text of the answer it self