1

I have 3 tables in my database. A link table, a question table and an answer table. In link I store evaluationmoments. In question I store the questions that can be asked in the evaluations. In answer I store the answers that a user has given in the evaluation. What I want to do is get all the answers that were given for a specific evaluation.

Link has the primary key link_ID. Question has the primary key question_ID. Answer has the primary key anwer_ID.

Link and Question are connected with a many-to-many relationship. Therefore there is a pivot table called link_question. With the keys link_id and question_id.

In my laravel models I have these functions:

class Link extends Ardent{
public function question(){
    return $this->belongsToMany('Question');
}

class Question extends Ardent{

public function link(){
    return $this->belongsToMany('Link');
}

This all works fine. However, now I want to give the answer table a many-to-one relation with this pivot table. For every entry in the pivot table there are multiple answers. How would I got about implementing this in laravel? I don't have a model for the pivot table so I can't just add a function there.

RemcoW
  • 4,196
  • 1
  • 22
  • 37
  • You can help from this answer about pivot tables and query http://stackoverflow.com/questions/23336145/laravel-how-to-use-multiple-pivot-table-relationships?answertab=votes#tab-top – Kabir Hossain Apr 23 '16 at 04:55

0 Answers0