实际上我是 laravel 的新手,我尝试从 10 公里纬度和经度以下的 Sql 获取用户,但它的抛出错误。错误是——方法 Illuminate\Support\Collection::SQRT 不存在。这是我的控制器代码<?phpnamespace App\Http\Controllers;use Illuminate\Foundation\Auth\Access\AuthorizesRequests;use Illuminate\Foundation\Bus\DispatchesJobs;use Illuminate\Foundation\Validation\ValidatesRequests;use Illuminate\Routing\Controller as BaseController;use DB;class Controller extends BaseController{ use AuthorizesRequests, DispatchesJobs, ValidatesRequests; public function index() { $users = DB::table('users') ->select('id','name','phone','latitude','longitude') ->get() ->SQRT("POW(69.1 * (latitude - 24.900110), 2) + POW(69.1 * (67.099760 - longitude) * COS(latitude / 57.3), 2)) AS distance") ->having("distance < 25") ->orderBy("distance"); return view('userview', compact('users')); }}
1 回答
子衿沉夜
TA贡献1828条经验 获得超3个赞
你可以试试这个——
$users = DB::table('users') ->select(DB::raw('id,name,phone, 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') ->get();
- 1 回答
- 0 关注
- 78 浏览
添加回答
举报
0/150
提交
取消