title: Laravel distance query in repository
body: <p>I use Laravel 5.4 and I want to use distance in Eloquent.</p>
  
  <p>In my repository, I have :</p>
  
  <pre><code>public function getRecommended($lat, $lng, $distance, $n)
  {
      \DB::enableQueryLog();
      $raw = \DB::raw('ROUND ( ( 6371 * acos( cos( radians('.$lat.') ) * cos( radians( ad_latitude ) ) * cos( radians( ad_longitude ) - radians('.$lng.') ) + sin( radians('.$lat.') ) * sin( radians( ad_latitude ) ) ) ) ) AS distance');
  
      $data = $this-&gt;queryGetAds()-&gt;addSelect($raw)-&gt;orderBy( 'distance', 'ASC' )-&gt;groupBy('distance')-&gt;having('distance', '&lt;=', $distance)-&gt;paginate($n);
      dd(\DB::getQueryLog());
  }
  </code></pre>
  
  <p>The error is : </p>
  
  <blockquote>
    <p>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in
    'group statement'</p>
  </blockquote>
  
  <p>I checked by removing </p>
  
  <pre><code>-&gt;orderBy( 'distance', 'ASC' )-&gt;groupBy('distance')-&gt;having('distance', '&lt;=', $distance)
  </code></pre>
  
  <p>And the debugging shows the good query with $raw statement in. I am in a repository.</p>
  
  <p>Is there something missing ?</p>