Sunday, 8 August 2021

Laravel Eloquent orWhere

 https://stackoverflow.com/questions/16995102/laravel-4-eloquent-query-using-where-with-or-and-or

# for orWhere to work, you have to have a where first


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

Or you can do 

Model:where()->orWhere()



No comments:

Post a Comment