title: Laravel Orderby Calculated Value
body: <p>I have this function which should return values by distance, closer to further away. However receiving this error in Laravel: Use of undefined constant lat - assumed 'lat' </p>
  
  <p>Code as follows:</p>
  
  <pre><code>public static function getNearby($lat, $lng, $distance = 50, $limit = 50) {
  
      $radius = 6371.009; // Earths radius in KM
  
      // Latitude Boundaries
      $minLat = (float) $lat - rad2deg($distance / $radius);
      $maxLat = (float) $lat + rad2deg($distance / $radius);
  
      // Longitude Boundaries
      $minLng = (float) $lng - rad2deg($distance / $radius / cos(deg2rad((float) $lat)));
      $maxLng = (float) $lng + rad2deg($distance / $radius / cos(deg2rad((float) $lat)));
  
      // Query DB
      $nearby = (array) DB::table('users')
          -&gt;where('lat', '&gt;', $minLat)
          -&gt;where('lat', '&lt;', $maxLat)
          -&gt;where('lng', '&gt;', $minLng)
          -&gt;where('lng', '&lt;', $maxLng)
          -&gt;orderBy(ABS(lat - (float) $lat) + ABS(lng - (float) $lng), 'ASC')
          -&gt;take($limit)
          -&gt;get(); 
  
      var_dump($nearby);
  
  }
  </code></pre>
  
  <p>Any suggestions here? I envisage I may have to do a DB:raw but am unsure how to incorporate that (if I have to)... Appreciate the help, thanks.</p>