The parent is Exam, the child of Exam is Question, and the child of Question is Choices
I wanted to display all questions of this certain exam (exam_id) with its corresponding choices.
Exam Model
public function questions()
{
return $this->hasMany('App\Questions');
}
Question Model
public function exams()
{
return $this->belongsTo('App\Exam', 'exam_id', 'exam_id');
}
public function choices()
{
return $this->hasMany('App\Choice');
}
Choice Model
public function questions()
{
return $this->belongsTo('App\Question', 'question_id', 'question_id');
}
In Controller
$all = Exam::with(['questions','questions.choices'])->where('exam_id', $examID)->get();
I don't seem to get the desired result. It throws an error of Class 'App\Questions' not found. I just started laravel hope someone could help me out. Thanks.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Hv3mZs
via IFTTT
Aucun commentaire:
Enregistrer un commentaire