lundi 27 juin 2016

Passing query builder instances into function call with eloquent queries

An Employee has many employeeAreas, wanting to return any Employees who have at least one employeeArea that is within 12km of any of points in the $latLngCol collection.

Getting SQL syntax errors and I am not sure how to use the $ea query builder instance to project the latitude and longitude properties of employeeArea objects into the function call.

public static function findClosest($latLngCol) {

    $employees = Employee::where('employeeareas',function($query) use($latLngCol) {

        $query->where(function($ea) use($latLngCol)  { 

            $latLngCol->first(function($key, $val) use($ea) {


                 $m = DistanceCalculator::LatLngToLatLng($val['lat'],$val['lng'],$ea->select('latitude')->first(), $ea->select('longitude')->first());

                if($m <= 12000) return true;


        });  

        }

       )->first();
    }); 


    return $employees;


}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire