with([ 'person' => function ($query) { $query->select(['name']); }, 'speciality' => function ($query) { $query->select(['id', 'name']); }, ]) ->where('active', 1) ->whereNot('speciality_id') ->get(['id', 'speciality_id']) ->random($limit); $data = DoctorResourceDashboard::collection($queryDoctors); } elseif ($query === 'hospitals') { $queryHospitals = Organization::query() ->leftJoin('addresses', function ($query) { $query->on('organizations.main_address_id', '=', 'addresses.id'); $query->where('addresses.addressable_type', '=', Organization::class); }) ->where('organizations.type', 'hospital') ->where('organizations.status', 'active') ->when($request->lat && $request->lng, function ($query) use ($request) { $query->selectRaw("organizations.id, organizations.name, addresses.text AS currentAddress, 6371 * acos (cos ( radians($request->lat) ) * cos( radians( addresses.lat ) ) * cos( radians( addresses.lng ) - radians($request->lng) ) + sin ( radians($request->lat) ) * sin( radians( addresses.lat ) )) as distance"); $query->orderBy('distance', 'ASC'); }, function ($query) { $query->select(['organizations.id', 'organizations.name', 'addresses.text AS currentAddress']); $query->orderBy('organizations.name', 'asc'); }) ->limit($limit) ->get(); $data = HospitalResourceDashboard::collection($queryHospitals); } elseif ($query === 'articles') { $data = ArticleResourceDashboard::collection(json_decode(Http::get('https://linksehat.com/api/medical-assistance-articles'))); } return response()->json([ 'status' => 'success', 'statusCode' => Response::HTTP_OK, 'message' => 'Data berhasil di ambil', 'data' => $data, ]); } }