我正在使用Laravel查询生成器根据用户的筛选 Select 动态筛选数据:
$query = DB::table('readings');
foreach ($selections as $selection) {
$query->orWhere('id', $selection);
}
$query->whereBetween('date', array($from, $to));
$query->groupBy('id');
当我判断SQL时,我得到如下结果:
select count(*) as `count` from `readings` where `id` = 1 or id` = 2 and `date` between "2013-09-01" and "2013-09-31" group by `id`;
但我需要的是这样的东西(或语句周围有括号):
select count(*) as `count` from `readings` where (`id` = 1 or id` = 2) and `date` between "2013-09-01" and "2013-09-31" group by `id`;
如何使用Laravel查询生成器在WHERE条件周围添加括号?