title: How to sort query results by distance in Laravel QueryBuilder / MySQL Spatial package?
body: <p>First I want to show you the current database structure. There are three tables:</p>
  
  <p><strong>dishes</strong> (id, name)</p>
  
  <p><strong>locations</strong> (id, name, coordinates (POINT))</p>
  
  <p><strong>dish_location</strong>(location_id, dish_id)</p>
  
  <p>Now I want to implement an API which gets the position (latitude, longitude) of the user and returns a list of dishes sorted by the distance in km. I already have a method which takes two latitudes and two longitudes and gives me the distance. But I am sure you can show me a way, which is a more performant way to do this directly in the MySQL query.</p>
  
  <p><strong>Additional:</strong> I want to do a "load more"-function in the API. So I pass the count of already received items or how would I solve this in this case?</p>
  
  <p>I am using this for the <a href="https://github.com/grimzy/laravel-mysql-spatial" rel="nofollow noreferrer">MySQL Spatial package</a></p>