Get Current and Historical Currency Exchange Rates in Laravel

Packages

May 6th, 2021

laravel-currency-featured.png

Laravel Currency is a package that provides current and historical exchange rates for currency and cryptocurrencies. The package leverages the exchangerate.host API for exchange rate data, and has a clean API for getting data:

1use AmrShawky\Currency\Facade\Currency;
2 
3// Get the current USD -> EUR exchange rate
4Currency::convert()
5 ->from('USD')
6 ->to('EUR')
7 ->get();
8 
9// Historical exchange rate data
10Currency::convert()
11 ->from('USD')
12 ->to('EUR')
13 ->date('2019-08-01')
14 ->get();
15 
16// Get all of the latest rates
17Currency::rates()
18 ->latest()
19 ->get();
20 
21// A more complete example, getting historical rates
22Currency::rates()
23 ->historical('2020-01-01')
24 ->symbols(['USD', 'EUR', 'CZK'])
25 ->base('GBP')
26 ->amount(5.66)
27 ->round(2)
28 ->source('ecb')
29 ->get();

You can learn more about this package, get full installation instructions, and view the source code on GitHub. You can learn more about the exchangerate.host API by reading the official API documentation.


This package was submitted to our Laravel News Links section. Links is a place the community can post packages and tutorials around the Laravel ecosystem. Follow along on Twitter @LaravelLinks

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.