ash-jc-allen / laravel-exchange-rates

A Laravel wrapper package for interacting with the exchangeratesapi.io API.
MIT License
449 stars 49 forks source link

Get the exchange rate for multiple currencies at once #34

Closed ash-jc-allen closed 4 years ago

ash-jc-allen commented 4 years ago

At the moment if you want to get the exchange for multiple currencies, you'd have to make multiple method calls. As an example, to get the exchange rates for EUR to GBP and EUR to USD, you'd have to do the following:

$eurExchangeRate = $exchangeRates->exchangeRate('GBP', 'EUR');
$usdExchangeRate = $exchangeRates->exchangeRate('GBP', 'USD');

This could be updated so that the second parameter accepts an array of currencies. By doing this, we can then return the multiple exchange rates at once. We might be able to do all this under-the-hood by making just one call to the API; otherwise we'll have to make multiple calls and build up the array ourselves.

Potential example of proposed change:

$eurUsdExchangeRate = $exchangeRates->exchangeRate('GBP', ['EUR', 'USD']);

// $eurUsdExchangeRate would be equal to:
[
    'EUR' => 11111,
    'USD' => 22222,
]
ash-jc-allen commented 4 years ago

This feature was added in release v3.0.0.