Stephen Bugs Kamenar Stephen Bugs Kamenar - 3 months ago 13
PHP Question

Laravel 4 eloquent WHERE with OR AND OR?

How do I say

WHERE (a=1 OR b=1) AND (c=1 OR d=1)


For more complicated queries am I supposed to use raw SQL?

Answer

Make use of Advanced Where Clauses (Laravel 5.2). For your example, it'd be something like this:

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