There's an Employee model and many coveredArea models that belong to Employee.
Employee
int id
string name
CoveredArea
int id
int employee_id
decimal lat
decimal lng
I need to check if any of the coveredArea belonging to Employees are within 12km of latitude and longitude points contained in a collection of arrays called JobLocations and return these Employees.
public static function findClosest($jobLocations) {
Employee::where('coveredareas',function($query) {
$query->where(function($ca) {
$jobLocations->first(function($key, $val) {
$m = DistanceCalculator::LatLngToLatLng($val['lat'],$val['lng'],$ca->lat, $ca->lng);
if($m <= 12000) return true;
});
}
)->first();
});
}
I am unsure how to properly pass the LatLngToLatLng() function and lat and lng variables on the coveredAreas object that I presume should be on the $ca variable.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire