php - Laravel query escaping the period (.) -


i'm in process of updating api based on laravel.

using eloquent db model i've written scope narrow down query of require.

the issue i'm facing we're trying pass in latitude/longitude co-ords query, should used pull out users in radius of given point.

the query works fine when entered manually, when dumping sql after calling scope, has escaped . within float.

code:

public static function scopeinradius($query, $lat, $lng, $distance = 50) {         $qstring = '         ( 3959 * acos(             cos( radians( '.$lat.') )           * cos( radians( latitude ) )           * cos( radians( longitude) - radians('.$lng.') )           + sin( radians( '.$lat.') )           * sin( radians( latitude ) )                      )         )';     return $query->where($qstring, '<', $distance); } 

on var_dump()'ing ->tosql(), i'm presented following output:

string 'select * `users` `users`.`deleted_at` null , `         ( 3959 * acos(             cos( radians( 53`.`258100) )           * cos( radians( latitude ) )           * cos( radians( longitude) - radians(2`.`127400) )           + sin( radians( 53`.`258100) )           * sin( radians( latitude ) )                      )         )` < ?' (length=376)`` 

i'm sure there must method escape these periods, though yet i've been unable find it! appreciated!

use whereraw instead of where, make sure cast parameters float security reasons:

$lng = floatval($lng); $lat = floatval($lat); $distance = floatval($distance);  return $query->whereraw($qstring . ' < ' . $distance); 

Comments