Ad

I Have This SQL Query Working And I Want To Migrate To The Laravel Query Builder Format

- 1 answer

Today is working with this SQL Query.

 SELECT me.id
 FROM refrees r
 LEFT JOIN matches m
 ON m.refree_id = r.id
 LEFT JOIN match_events me
 ON m.id = me.match_id
 WHERE  r.id = 1
 AND me.match_event_type_id = 2

I have tried it, but its not working.

 $c = DB::table('refrees as r')
 ->leftJoin('matches as m', 'r.id', '=', 'm.refree_id')
 ->leftJoin('match_events as me', 'me.id', '=', 'm.id')
 ->where('r.id', '=', '1')
 ->where('me.match_event_type_id', '=', '2')
 ->select('me.id')
 ->get();
Ad

Answer

My bad. It was

 ->leftJoin('match_events as me', 'me.id', '=', 'm.id') 

where I would put

 ->leftJoin('match_events as me', 'me.id_match', '=', 'm.id')
Ad
source: stackoverflow.com
Ad