lundi 20 février 2017

Trying to fetch by id from one table which has multiple answers in another table

I have a questions table which contains all the questions. I also have a answers table which contains all the answers. A question can have multiple answers and an answer belongs to only one question. So the problem is how can i fetch a question by it's id and it should also have all the answers that belong to this question.

Answer Model

class Answer extends Model
{
    public function question()
    {
        return $this->belongsTo('App\Question');
    }
}

Question Model

class Question extends Model
{

    public function answers()
    {
        return $this->hasMany('App\Answer');
    }
}

How can i write a query, I have tried few but I am confused now



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lDDxvr
via IFTTT

Aucun commentaire:

Enregistrer un commentaire