Я использую Laravel 5 и имею 2 модели location
и chauffeur
с отношениями
public function chauffeurs() { return $this->hasMany('App\Chauffeur'); }
и
public function location() { return $this->hasOne('App\Location', 'id', 'location_id'); }
Это мой запрос, который работает
"SELECT *,
(6371 * acos(cos(radians(".$latitude.")) * cos(radians(latitude)) * cos(radians(longitude) - radians(".$longitude.")) + sin(radians(" . $latitude.")) * sin(radians(latitude)))) AS distance
FROM `locations` AS l
JOIN `chauffeurs` AS c
ON (l.id = c.location_id)
HAVING distance < c.radius
ORDER BY distance ";
Это то, что у меня есть
Chauffeur::select('*, (6371 * acos(cos(radians(1.492659)) * cos(radians(latitude)) * cos(radians(longitude) - radians(103.7413591)) + sin(radians(1.492659)) * sin(radians(latitude)))) AS distance ')
->join('Location', '`location`.`id`', '=', '`chauffeur`.`location_id`')
->havingRaw('distance < `chauffeur`.`radius`')
->get();
, и я получаю эту ошибку
`Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`492659)) * sin(radians(latitude))))` as `distance ` from `locations` inner joi'`
Как бы я использовал модели Laravel для того же запроса?Есть идеи, что я делаю не так или есть лучший способ?Спасибо