I would like to create a structure with models for exam app.
Basic models structure that i would imagine:
- exam
- questions ( exam has many questions ) { i think that should be morphed table }
questions should have option to add multiple type of questions that are specified bellow
- openQuestions - question type
- closedQuestions - other question type
- .... - more question types
- questions ( exam has many questions ) { i think that should be morphed table }
questions should have option to add multiple type of questions that are specified bellow
So I would like to have a structure like:
exam have many questions and to questions table, I want to add any type of model that extends my question Model which always contains 2 params ( 'question', 'max_points', and other fields specified for questions )
I want to add a relation between exams table and questions table, between questions table and closed_questions table and questions to open_questions.
So what I have tried:
I added relations for each question type to exams model morphedByMany(QuestionModelType::class,'questions') something like :
Exams.php //Model
public function openQuestions()
{
return $this->morphedByMany(OpenQuestion::class, 'questions');
}
public function closedQuestions()
{
return $this->morphedByMany(ClosedQuestion::class, 'questions');
}
I can operate on models but I don't think that's an ideal solution, or should I just leave it as it is. I think there is a nicer way of doing this, but I'm not familiar with this. Or should I just add a Relation that morphs over an array of all question types? How it should work when I would like to extend app with a new question type?