如何在Laravel雄辩的“OR”条件中应用“和”条件

时间:2014-05-06 07:06:53

标签: php sql laravel eloquent where-clause

我的查询就像

SELECT * FROM activities WHERE (active=1 AND linked_project_id IN (2,3) AND GLOBAL=1 OR (linked_project_id=2  AND active=1))

但我不知道如何把#linked; project_project_id = 2 AND active = 1'这里面和Laravel。 这是我的代码 -

$activities=  Activitie::where('active','=',1)->whereIn('linked_project_id',array(2,3))->where('global','=','1')->orWhere('linked_project_id','='2)->where('active','=',1)->get();

但这会产生像

这样的结果
SELECT * FROM activities WHERE (active=1 AND linked_project_id IN (2,3) AND GLOBAL=1 OR (linked_project_id=2 ) AND active=1)

1 个答案:

答案 0 :(得分:1)

利用Advanced Wheres

Model::where(function ($query) {
    $query->where('a', '=', 1)
          ->orWhere('b', '=', 1);
})->where(function ($query) {
    $query->where('c', '=', 1)
          ->orWhere('d', '=', 1);
});