mercredi 27 mars 2019

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'answers.question_id' in 'where clause'

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) 
     //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 answers where answers.question_id = 5 and answers.question_id is not null) (View: C:\Users\harsh\sa1\resources\views\questions\show.blade.php)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire