public function getMapData($requestData){
$radius = 50;
$query = Community::query();
$query->withCount('feedbacks');
if((isset($requestData->search_data['location'])
&& !empty($requestData->search_data['location']))
|| ($requestData->search_data['location']!=NULL)){
&& !empty($requestData->search_data['location']))
|| ($requestData->search_data['location']!=NULL)){
$query->where(DB::raw("( 6371 * acos( cos( radians
(".$requestData->search_data['location']['lat'].") ) *
(".$requestData->search_data['location']['lat'].") ) *
cos( radians( communities.lat ) ) *
cos( radians( communities.lang ) -
radians(".$requestData->search_data['location']['lan'].") ) +
radians(".$requestData->search_data['location']['lan'].") ) +
sin( radians(".$requestData->search_data['location']['lat'].") ) *
sin( radians( communities.lat ) ) ) )
sin( radians( communities.lat ) ) ) )
"),'<',$radius);
}else{
$query->where(DB::raw("( 6371 * acos( cos( radians(3.119008) ) *
cos( radians( communities.lat ) ) *
cos( radians( communities.lang ) - radians(101.678833) ) +
sin( radians(3.119008) ) * sin( radians( communities.lat ) ) ) )
"),'<',$radius);
}
return $query->paginate(20);
}
Comments
Post a Comment