我怎么说WHERE (a = 1 OR b =1 ) AND (c = 1 OR d = 1)
WHERE (a = 1 OR b =1 ) AND (c = 1 OR d = 1)
对于更复杂的查询,我应该使用原始 SQL 吗?
利用逻辑分组(Laravel 7.x / 4.2)。对于您的示例,它将是这样的:
Model::where(function ($query) { $query->where('a', '=', 1) ->orWhere('b', '=', 1); })->where(function ($query) { $query->where('c', '=', 1) ->orWhere('d', '=', 1); });