我正在尝试使用形式通过纬度和经度从10公里记录下的数据库获取数据,但我面临着erorr
埃罗尔
Illuminate\Database\QueryException SQLSTATE[42S22]: 列未找到: 1054 “have clause” 中的未知列 'distance' (SQL: select count(*) 作为距离< 25 的聚合)users
网.php
Route::get('/map','MapController@index');
Route::get('/userview','MapController@getUserByLatLong');
Route::post('/showdata','Mapcontroller@showdata');
User.blade.php
<form method="POST" action="{{ action('Mapcontroller@showdata') }}">
@csrf
<lable>Latitude</lable>
<input type="text" name="latitude" /><br>
<lable>Longitude</lable>
<input type="text" name="longitude" /><br>
<lable>Kilomneter</lable>
<input type="text" name="kilometer" /><br>
<input type="submit" name="submit" /><br>
</form>
控制器代码
public function showdata(Request $request)
{
$this->validate($request, [
'latitude' => 'required',
'longitude' => 'required'
]);
$latitude = $request->input('latitude');
$longitude = $request->input('longitude');
$users = DB::table('users')
->select(DB::raw($latitude,$longitude, 'SQRT(POW(69.1 * (latitude - 24.900110), 2) + POW(69.1 * (67.099760 -longitude) * COS(latitude / 57.3), 2)) AS distance'))
->havingRaw('distance < 25')
->OrderBy('distance')
->paginate(10)
->get();
echo $users;
return view('userview',['users' => $users]);
}
慕尼黑的夜晚无繁华
紫衣仙女
三国纷争
慕后森