Stephen Bugs Kamenar Stephen Bugs Kamenar - 1 year ago 172
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 Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download