where('nId', $request->id) ->first(); return Helper::responseJson([ 'home' => HomeResource::make($user, $request), ]); } public function listHospital(Request $request){ // Hospital List $hospitalList = []; $hospitals = Organization::where([ 'type' => 'hospital', 'status' => 'active', ]) ->with('currentAddress') ->get()->toArray(); foreach($hospitals as $hospital){ $lat = 0; $lang = 0; if ($hospital['current_address']['lat']){ $lat = $hospital['current_address']['lat']; } if ($hospital['current_address']['lng']){ $lang = $hospital['current_address']['lng']; } $address = ''; if ($hospital['current_address']['text']){ $address = $hospital['current_address']['text']; } $radius = 0; if ($lat && $lang && $request->longitude && $request->latitude){ $radius = round(Helper::calculateDistance($lat, $lang, $request->latitude, $request->longitude), 2); } $data = [ 'name' => $hospital['name'], 'radius' => $radius, 'image' => '', 'address' => $address ]; array_push($hospitalList, $data); } usort($hospitalList, function($a, $b) { return $a['radius'] <=> $b['radius']; }); return Helper::responseJson([ 'hospital' => $hospitalList ]); } }