Select nearest cities from table

Posted 5 months ago by engrlaravel

I have saved all cities in my database with field type POINT. To save in model i did like this

use Spatial; protected $spatial = ['location'];

I have only one column for that. there is no seperate columns in my table. so this query not applicable

$results = DB::select(DB::raw('SELECT id, ( 3959 * acos( cos( radians(' . $lat . ') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(' . $lng . ') ) + sin( radians(' . $lat .') ) * sin( radians(lat) ) ) ) AS distance FROM articles HAVING distance < ' . $distance . ' ORDER BY distance') );

How i can create query in eloquent for this ??

Please sign in or create an account to participate in this conversation.