简体   繁体   中英

Getting Users From Sql Under 10km Latitude and Longitude

actually I am new in laravel and i try Getting Users From Sql Under 10km Latitude and Longitude but its throwing error. Error is-

Method Illuminate\\Support\\Collection::SQRT does not exist.

Here is my controller code

<?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'));

    }
}

You can try this -

$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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM