@tykus & @sinnbeck , thank you for all your response, you will find more details below.
This is all the codes in Answer Model
class Answer extends Model
{
protected $fillable = [
'question_id',
'slug',
'answer_text',
'is_correct',
'background',
'disc',
];
public function sluggable()
{
return [
'slug' => [
'source' => 'answer_text'
]
];
}
public function questions(){
return $this->belongsTo(Questions::class);
}
}
and here all the code in Questions Model
class Questions extends Model
{
protected $fillable = [
'question_title',
'slug',
'quiz_id',
'background',
];
public function sluggable()
{
return [
'slug' => [
'source' => 'question_title'
]
];
}
public function result(){
return $this->hasMany(Result::class);
}
public function answers(){
return $this->hasMany(Answer::class);
}
public function quiz(){
return $this->belongsTo(Quizzes::class);
}
public function getQuestionById($id){
return Question::find($id);
}
}
When I view the questions separately in QuestionsController@show()
public function show(Questions $question)
{
$answers = Answer::where('question_id', $question->id)->get();
$result = Result::where('question_id', $question->id)->get();
return view('admin.question.show', compact('question', 'answers', 'result'));
}
it retraive the all the answers without any issues.
But When I want to view all details of the quiz, like questions and answers on the same page it appears the issue