jeudi 1 novembre 2018

How get data in method from others tables?

enter image description here

This is my simple db schema. Now in my group table i have 'group_A' and 'group_B'. In questions table i have 10 questions 5 for group_A and 5 for group_B. Users table is one user with ID = 1. What i try to do is get data like this:

SELECT answer
FROM answers
JOIN questions q ON (q.id = answer.question_id)
JOIN group g ON (g.id = q.group_id)
WHERE user_id = 1 AND g = 'group_A'

I have model in users class and i would like create method to get answers depend from group:

public function getAnswers($group) {
        return $this->hasMany('App\Answers', 'question_id', 'id');
    }

How can i get this in that method ? Should i create method group in questions class ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire