实际上我是 laravel 的新手,我尝试从 10 公里纬度和经度以下的 Sql 获取用户,但它的抛出错误。错误是——
方法 Illuminate\Support\Collection::SQRT 不存在。
这是我的控制器代码
<?php
namespace 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'));
}
}
子衿沉夜