How to use Laravel Eloquent Query Using WHERE with OR AND OR Code answer – 2024

In this article, we will learn about how to use Laravel Eloquent Query Using WHERE with OR AND OR

1). Laravel Eloquent Query Using WHERE with OR AND OR?

Source: stackoverflow.com

Make use of Logical Grouping (Laravel 7.x/4.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);
});

Discover more from STRUGGLER KING.COM

Subscribe now to keep reading and get access to the full archive.

Continue Reading