我想完成这样的事情:
SELECT *
FROM table1
LEFT JOIN table2 ON (table1.id=table2.id OR table1.tid=table2.tid) AND table1.x=table2.x
在Laravel中会变成这样:
TABLE1::leftJoin('table2', function($join){
$join->on('table1.id','table2.id')->orOn('table1.tid','table2.tid');
$join->on('table1.x','table2.x');
})->get()
我只是不确定如何在Eloquent的查询中使用OR括号?
找到了:
TABLE1::leftJoin('table2', function($join){
$join->on(function($join2) {
$join2->on('table1.id','table2.id');
$join2->orOn('table1.tid','table2.tid');
});
$join->on('table1.x','table2.x');
})->get()