title: Laravel, MySQL Spatial Point distance: orderBy and get distance
body: <p>Can anyone help me get this query right.</p>
  
  <p>I have a <code>Concert</code> model and another <code>Location</code> model. Concert belongs to a location. Location table has a spatial point field.</p>
  
  <p>I need to do three things:</p>
  
  <ul>
  <li>order by distance from users location</li>
  <li>display distance from users location</li>
  <li>get concerts that are in some given distance from the users location</li>
  </ul>
  
  <p>So far I have managed to set the database and to get the concerts in a certain distance from the user as:</p>
  
  <pre><code>$condition = ($lat != null &amp;&amp; $lon != null &amp;&amp; $distance != null);
  Concert::when($condition, function ($query) use ($distance,$lat,$lon) {
        return $query-&gt;whereHas('location', function($query) use ($distance,$lat,$lon) {
            $query-&gt;whereRaw('st_distance(location,POINT('.$lat.','.$lon.')) &lt; '.$distance);
        });
    })
  -&gt;get();
  </code></pre>
  
  <p>Can you help me how to display this <code>st_distance</code> in the view?</p>
  
  <p>How would I order this by distance?</p>
  
  <p>What is the proper way to get the <code>$distance</code> in miles/kilometers as I read in the docs that <code>st_distance</code> is given in degrees?</p>