I'm trying to make a relation
Question hasMany Answer
Question.php
public function answers()
{
return $this->hasMany(Answer::class);
}
then displaying Answers for a Question in show.blade.php like:
@foreach($question->answers as $answer)
{{$answer->ans}} //ans is the answers body from database
@endforeach
Getting this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'answers.question_id' in 'where clause' (SQL: select * from
answerswhereanswers.question_id= 5 andanswers.question_idis not null) (View: C:\Users\harsh\sa1\resources\views\questions\show.blade.php)

question_id!=q_id- you need to be consistent with your naming of columns, otherwise specify it explicitly inhasMany(). Easier to just renameq_idtoquestion_id. - Qirel