Currency translator code example

Example 1: currency converter

currency convertor

Example 2: currency conversion

$from = 'USD';
$to = 'INR';
$cacheKey = 'convertCurrency' . $from . 'To' . $to;

$rate = Cache::remember($cacheKey, 60 * 12, function () use ($from, $to) {
  $converterUrl = 'https://free.currencyconverterapi.com/api/v6/convert?q=' . $from . '_' . $to . '&compact=ultra&apiKey=' . env('CURRENCY_CONVERTER_API_KEY');
  $data = file_get_contents($converterUrl);
  $json = json_decode($data, true);
  return implode(" ",$json);
});

$convertedCurrency = $rate * $amount;

Tags:

Misc Example