在Laravel 5.3中从6.x开始仍然适用,您可以使用更细粒度的wheres作为数组传递:
$query->where([ ['column_1', '=', 'value_1'], ['column_2', '<>', 'value_2'], [COLUMN, OPERATOR, VALUE], ...])
就个人而言,我并没有在多个
where调用中找到用例,但事实是您可以使用它。
自2014年6月起,您可以将数组传递给where
只要您想要所有
wheres使用
and运算符,就可以通过以下方式将它们分组:
$matchThese = ['field' => 'value', 'another_field' => 'another_value', ...];// if you need another group of wheres as an alternative:$orThose = ['yet_another_field' => 'yet_another_value', ...];
然后:
$results = User::where($matchThese)->get();// with another group$results = User::where($matchThese) ->orWhere($orThose) ->get();
上面将导致这样的查询:
SELECt * FROM users WHERe (field = value AND another_field = another_value AND ...) OR (yet_another_field = yet_another_value AND ...)



