title: Laravel query builder - re-use query with amended where statement
body: <p>My application dynamically builds and runs complex queries to generate reports. In some instances I need to get multiple, somewhat arbitrary date ranges, with all other parameters the same. </p>
  
  <p>So my code builds the query with a bunch of joins, wheres, sorts, limits etc and then runs the query. What I then want to do is jump into the Builder object and change the where clauses which define the date range to be queried. </p>
  
  <p>So far, I have made it so that the date range is setup before any other wheres and then tried to manually change the value in the relevant attribute of the wheres array. Like this;</p>
  
  <pre><code>$this-&gt;data_qry-&gt;wheres[0]['value'] = $new_from_date;
  $this-&gt;data_qry-&gt;wheres[1]['value'] = $new_to_date;
  </code></pre>
  
  <p>Then I do (having already done it once already)</p>
  
  <pre><code>$this-&gt;data_qry-&gt;get();
  </code></pre>
  
  <p>Doesn't work though. The query just runs with the original date range. Even if my way worked, I still wouldn't like it though as it seems to be shot through with a precarious dependence (some sort of coupling?). Ie; if the date wheres aren't set up first then it all falls apart. </p>
  
  <p>I <em>could</em> set the whole query up again from scratch, just with a different date range, but that seems ott as everything else in the query needs to be the same as the previous time it was used. </p>
  
  <p>Any ideas for how to achieve this in the correct / neatest way are very welcome. </p>
  
  <p>Thanks,</p>
  
  <p>Geoff</p>