I am trying to join three tables in my application. Below you can check the example table structure
Table A
----------------
| a_id | b_fk |
----------------
| 1 | 2 |
----------------
| 2 | 2 |
----------------
Table b
----------------
| b_id | c_fk |
----------------
| 1 | 1 |
----------------
| 2 | 1 |
----------------
Table C
----------------
| c_id | value|
----------------
| 1 | aaa |
----------------
| 2 | ccc |
----------------
I want to join these three table and implement join with precedence using Laravel query builder
SELECT * FROM a LEFT JOIN (b JOIN c ON (b.c_kf = c.id)) ON (a.b_fk = b.id);
I've tried to do something like this
DB::table('a')->leftJoin('b', function ($join){
$join->leftjoin('c', 'b.c_fk', '=', 'c.id')
->on('a.b_fk', '=', 'b.id');
})
Which forms following query
SELECT * FROM a LEFT JOIN b ON (a.b_fk = b.id);
Is there a way to join multiple tables in Laravel and implement precedence?