Skip to content

Instantly share code, notes, and snippets.

@hewerthomn
Created February 21, 2016 13:58
Show Gist options
  • Save hewerthomn/42ae1097e1ce8ba8de4e to your computer and use it in GitHub Desktop.
Save hewerthomn/42ae1097e1ce8ba8de4e to your computer and use it in GitHub Desktop.
Filter places by coordinates radius
<?php
$latlng = "-8.769926868691913 -63.88429307573199";
$radius = 5000;
$places = Place::where(DB::raw("ST_Distance_Sphere(places.latlng, ST_GeometryFromText('SRID=4326;POINT({latlng})'))"), '<', $radius)
->select('offers.*', DB::raw("ST_Distance_Sphere(places.latlng, ST_GeometryFromText('SRID=4326;POINT({$latlng})')) AS distance"))
->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment