title: How to use paginate() with a having() clause when column does not exist in table
body: <p>I have a tricky case ...</p>
  
  <p>Following database query does not work:</p>
  
  <pre><code>DB::table('posts')
  -&gt;select('posts.*', DB::raw($haversineSQL . ' as distance'))
  -&gt;having('distance', '&lt;=', $distance)
  -&gt;paginate(10);
  </code></pre>
  
  <p>It fails with message: column distance does not exist.</p>
  
  <p>The error occurs when paginate() tries to count the records with</p>
  
  <pre><code>select count(*) as aggregate from {query without the column names}
  </code></pre>
  
  <p>As the column names are stripped, distance is not known and an exception is raised.</p>
  
  <p>Does somebody have a work around to be able to use pagination is this case ?</p>
  
  <p>Thanks</p>