updateCurrencies(); } } else { $this->updateCurrencies(); } } private function updateCurrencies() { info('updating currencies'); if (empty(config('ninja.currency_converter_api_key'))) { return; } $cc_endpoint = sprintf('https://openexchangerates.org/api/latest.json?app_id=%s', config('ninja.currency_converter_api_key')); $client = new \GuzzleHttp\Client(); $response = $client->get($cc_endpoint); $currency_api = json_decode($response->getBody()); /* Update all currencies */ Currency::all()->each(function ($currency) use ($currency_api) { $currency->exchange_rate = $currency_api->rates->{$currency->code}; $currency->save(); }); /* Rebuild the cache */ $currencies = Currency::orderBy('name')->get(); Cache::forever('currencies', $currencies); } }