1
我需要做一個查詢調用以下方法whereRaw調用方法:使用列名作爲參數
public function getDistanceFromLatLonInKm($lat1,$lon1,$lat2,$lon2) {
...
$d = R * c; // Distance in km
return $d;
}
我有「語法錯誤,意想不到的」「」嘗試添加時,「緯度」。和 '經度' 作爲參數:
public function show($lon, $lat, $radio) {
$results = Viaje::where($otherStuff)
->whereRaw('radio + ' . $radio . ' <= ' . $this->getDistanceFromLatLonInKm($lat, $lon, . 'latitude, longitude)');
return response()->json($results);
}
而在這條路上我遇到錯誤500:
public function show($lon, $lat, $radio) {
$results = Viaje::where($otherStuff)
->whereRaw('radio + ' . $radio . ' <= ' . $this->getDistanceFromLatLonInKm($lat, $lon, 32, 2));
return response()->json($results);
}
我怎麼能作出這樣的QUER y傳遞$ lat,$ lon作爲變量,'latitude','longitude'作爲每個寄存器的值。
感謝
正如你所說,我得到我的方法裏面如下:local.INFO:LAT1:51.5134,local.INFO:LAT2:緯度。 lat2和lon2將通過getDistanceFromLatLonInKm作爲字符串讀取,因此我得到錯誤500 – lulu666