[PHP] Laravel 联查中对不同表字段关系加条件的方式

如果条件需要加在 where 条件里,使用 whereColumn,如下示例:

whereColumn('A.b_id', '=', 'B.id');

如果需要加载 join 的 on 之后作为多个条件,使用匿名函数包裹,如下示例:

->leftJoin('B', function ($join) {
    $join->on('A.b_id', '=', 'B.id')
         ->on('A.hello', '!=', 'B.other_hello');
})

Link:https://www.cnblogs.com/farwish/p/13861834.html 

原文地址:https://www.cnblogs.com/farwish/p/13861834.html