我正在使用laravel 5應用程序。 我有問題從兩個數據庫表中獲取結果。這裏是我有:Laravel MySql連接表
table A: 'courses'
id | Course
————————————————
1 | Math
2 | History
3 | Geography
4 | Computer
和表B
user_id | classroom_id | course
1 | 5 | 3
1 | 5 | 4
1 | 6 | 2
我回到上一個表每個循環,但我想檢查哪些課程USER_ID 1必須返回true或false在for-each循環的每一列上。 事情是這樣的:
返回的項目爲USER_ID 1:
id | course | status
____________________________
1 | Math | false
2 | History | true
3 | Geography | true
4 | Computer | true
這是我有:
$AllList = DB::table('users')
->join('courses', 'users.id', '=', 'courses.parent_id')
->join('classroom', 'users.id', '=', 'classroom.user_id')->where('classroom_id', '=', 5)
->get();
任何幫助表示讚賞。
左連接應該這樣做,如果是空的,那麼它是'假' –
@ka_lin謝謝你評論,但代碼應該是什麼? –
到目前爲止你有什麼? –