I'm trying to find a solution to my problem but could not find anything useful. I need to get the "distance" variable that has been created by this query along with all the other data (user, userData, offers, and so on). I need to print the distance in 'km' within my view for every record i take. Is there someone who can help me please? Here's the code and hope its enough. Thanks a lot
if(property_exists($params, "lat") && property_exists($params, "lng")) {
if(null == $params->lat || null == $params->lng) {
//don't use coordinates
} else {
$radius = $this->coordMaxRadius;
$query->whereHas("userData", function($q) use ($params, $radius) {
$q->selectRaw( \DB::raw("
ROUND( 6371 * acos( cos( radians($params->lat) )
* cos( radians( lat ) )
* cos( radians( lng ) - radians($params->lng) )
+ sin( radians($params->lat) )
* sin( radians( lat ) ) ) ) AS distance "));
$q->having("distance", "<", $radius)->orderBy("distance");
});
}
}
............. later in the code.....
$query->with("timeSlots.days", "timeSlots.time", "userData", "university", "faculty", "user", 'userData.feedbacks');
.............
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jahrjn
via IFTTT
Aucun commentaire:
Enregistrer un commentaire