diff --git a/Http/Controllers/FrontendController.php b/Http/Controllers/FrontendController.php index f540e16..a4bd605 100644 --- a/Http/Controllers/FrontendController.php +++ b/Http/Controllers/FrontendController.php @@ -56,22 +56,34 @@ public function ont() { - $json = File::get('storage/kurs.json'); - $kurs = json_decode($json); - if($kurs->date != date('Y-m-d')){ + if (File::exists('storage/kurs.json')) { + $json = File::get('storage/kurs.json'); + $kurs = json_decode($json); + $date = Carbon::createFromTimestamp($kurs->time_last_update_unix)->format('Y-m-d'); + if ($date != date('Y-m-d')) { + $this->getKurs(); + } + } else { $this->getKurs(); } $json = File::get('storage/kurs.json'); $kurs = json_decode($json); - $usd = $kurs->rates->IDR/$kurs->rates->USD; - $date = Carbon::createFromTimestamp($kurs->timestamp)->locale('id')->setTimezone('Asia/Jakarta')->translatedFormat('d F Y H:i:s'); + $usd = $kurs->conversion_rate; - $sheets = Sheets::spreadsheet('1c2Uv3QVTyLzsJPE4uqqlMGNKO8z0Kqj6aEGh0uixAqA')->sheet('Platform')->range('A:F')->get(); - $header = $sheets->pull(0); - $posts = Sheets::collection($header, $sheets); - $posts = $posts->take(5000); - $data = new Collection($posts->toArray()); + $date = Carbon::createFromTimestamp($kurs->time_last_update_unix) + ->locale('id') + ->setTimezone('Asia/Jakarta') + ->translatedFormat('d F Y H:i:s'); + + $sheets = Sheets::spreadsheet('1c2Uv3QVTyLzsJPE4uqqlMGNKO8z0Kqj6aEGh0uixAqA') + ->sheet('Platform') + ->range('A:F') + ->get(); + $header = $sheets->pull(0); + $posts = Sheets::collection($header, $sheets); + $posts = $posts->take(5000); + $data = new Collection($posts->toArray()); $platform = $data->random(5); return view('frontend::ont', compact('kurs', 'usd','date','platform'));