get(); return response()->json([ 'allSubDistrict' => $allSubDistrict, ]); } public function excelParameterSubDistrict($latitude, $longitude, $year) { $subDistrict = SubDistrict::select('sub_district') ->where('latitude', $latitude) ->where('longitude', $longitude) ->first(); // dd($this->generateParameterSubDistrict($subDistrict['sub_district'], $latitude, $longitude)); $dataParameterSubDistrict = $this->generateParameterSubDistrict($subDistrict['sub_district'], $latitude, $longitude, $year); return Excel::download(new ParameterSubDistrictExport($dataParameterSubDistrict), 'parameter-cuaca-' . $subDistrict['sub_district'] . '-tahun-' . $year . '.xlsx'); // return view('website.apps.export.excel-parameter-subdistrict'); } public function generateParameterSubDistrict($subdistrict, $latitude, $longitude, $year) { $subDistrictParameter = []; $client = new Client(); $url = "https://power.larc.nasa.gov/api/temporal/monthly/point?start={$year}&end={$year}&latitude={$latitude}&longitude={$longitude}&community=ag¶meters=prectotcorr,T2M,WS2M,RH2M,ALLSKY_SFC_SW_DWN&format=json&header=true&time-standard=lst"; try { // Kirim permintaan GET ke URL $response = $client->request('GET', $url); $data = json_decode($response->getBody()->getContents(), true); $subDistrictParameter[$subdistrict] = [ $year, $data['properties']['parameter'], ]; } catch (\Exception $e) { // Tangani kesalahan jika terjadi echo "Error untuk latitude {$latitude} dan longitude {$longitude}: " . $e->getMessage() . "\n"; } return $subDistrictParameter; } }