@realrandyallen This works but when i replace the nos with requested latitude and longitude.It shows unexpected error inputs not found.How to provide the user input lat and lon. I wrote this but not working :
$inputs = \Input::all();
$datas = Doctor::selectRaw('(
6371* acos (
cos ( radians('$inputs['lat']') )
* cos( radians( lat ) )
* cos( radians( lon ) - radians('$inputs['lon']') )
+ sin ( radians('$inputs['lat']') )
* sin( radians( lat ) )
)
) AS distance')
->having('distance', '<', '5')
->orderBy('distance')
->limit(20)
->get();
Be very careful about creating sql injection weakness. If you are concatenating the lat and long into the search string, make sure you validate that they are only numbers and cannot be used to inject sql.