$pois = Home::select(\DB::raw('*, st_distance_sphere(homes.geopoint, point(?, ?)) as dist'))
->whereRaw('st_within(homes.geopoint, ST_Buffer(point(?, ?), 1))')
->orderBy('dist')
->get();
returns Laravel - SQLSTATE[HY000]: General error: 2031
However this query below works
$pois = Home::selectRaw('*, st_distance_sphere(homes.geopoint, point('.$data["lng"].', '.$data["lat"].')) as dist')
->whereRaw('st_within(homes.geopoint, ST_Buffer(point('.$data['lng'].', '.$data['lat'].'), 1))')
->orderBy('dist')
->get();
but it is vulnerable to SQLInjection. I've done the suggestions mentioned in stackoverflow. PDO error: General error: 2031 [duplicate]