title: How to add brackets around WHERE conditions with Laravel query builder
body: <p>I'm using the Laravel query builder to dynamically filter data based on a user's filter selections:</p>
  
  <pre><code> $query = DB::table('readings');
   foreach ($selections as $selection) {
     $query-&gt;orWhere('id', $selection);
   }
   $query-&gt;whereBetween('date', array($from, $to));
   $query-&gt;groupBy('id');
  </code></pre>
  
  <p>When I examine the SQL, I get something like this:</p>
  
  <pre><code>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`;
  </code></pre>
  
  <p>But what I need is something like this (with brackets around the or statements):</p>
  
  <pre><code>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`;
  </code></pre>
  
  <p>How do I add brackets around WHERE conditions with Laravel query builder?</p>