I'm not seeing a question here. Lol. Do you want to return both AnswerChoices and MatchingQAnswerChoices?
Question Model have ONE TO MANY relation-ship with AnswerChoice and MatchingQAnswerChoices. At a time either AnswerChoice or MatchingQAnswerChoices will point to Question,not both.
I have defined relation is below:-
public function AnswerChoices()
{
if($this->question_type_id =='5')
return $this->hasMany('App\MatchingQAnswerChoices');
else
return $this->hasmany('App\AnswerChoice','question_id');
}
But this relationship never returns MatchingQAnswerChoices data even if Question_Type=5.
Is there another approach to get data in this type of scenario?
thomastkim said:
I'm not seeing a question here. Lol. Do you want to return both AnswerChoices and MatchingQAnswerChoices? Yes. If I am using below code, its nor returning MatchingQAnswerChoices only AnswerChoices .
$quiz = App\Quiz::with('sections.questions.AnswerChoices');
Have you tried this?
$quiz = App\Quiz::with('sections.questions.AnswerChoices', 'sections.questions. MatchingQAnswerChoices')->where(['created_by'=>\Auth::user()->id, 'id' => $id])->get();
thomastkim said:
Have you tried this?
$quiz = App\Quiz::with('sections.questions.AnswerChoices', 'sections.questions. MatchingQAnswerChoices')->where(['created_by'=>\Auth::user()->id, 'id' => $id])->get();
Thanks for reply.Yes I am using this approach. But is it effective way? I mean is this best approach or we can tweak our Model Relationship bit more?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community