mardi 20 septembre 2016

Laravel MySql join table

I'm working on a laravel 5 application. I have issue getting results from two database table. here is what i have:

table A: 'courses' 

id   |    Course
————————————————
1    |    Math
2    |    History
3    |    Geography
4    |    Computer

and Table B

user_id | classroom_id | course 
1       | 5            | 3
1       | 5            | 4
1       | 6            | 2

I returned the table A on a for each loop but I would like to check what courses the user_id 1 has to return true or false on every column on the for-each loop. Something like this:

Returned item for user_id 1:

id   |    course     |  status
____________________________
1    |    Math       | false
2    |    History    | true
3    |    Geography  | true
4    |    Computer   | true

Any help appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire