Laravel Forex is a simple and flexible package for retrieving the latest and historical foreign exchange rates in your Laravel application.
By default, it uses the free tier from exchangerate-api.com, but you can easily configure it to use any other Forex provider.
Install via Composer:
composer require elegantly/laravel-forex
Publish the configuration file:
php artisan vendor:publish --tag="forex-config"
Here’s the default configuration that will be published to config/forex.php
:
use Elegantly\Forex\Integrations\ExchangeRateApiFree\ExchangeRateApiFreeConnector;
return [
'cache' => [
'enabled' => true,
'driver' => env('FOREX_CACHE_DRIVER', env('CACHE_DRIVER', 'file')),
'expiry_seconds' => 86_400, // 1 day
],
'rate_limit' => [
'enabled' => false,
'driver' => env('FOREX_RATE_LIMIT_DRIVER', env('CACHE_DRIVER', 'file')),
'every_seconds' => 3_600, // 1 hour
],
'client' => ExchangeRateApiFreeConnector::class,
'clients' => [
'exchange-rate-api' => [
'token' => env('EXCHANGE_RATE_API_TOKEN'),
],
],
];
use Elegantly\Forex\Facades\Forex;
$rates = Forex::latest('USD');
$usdToEur = $rates['EUR'];
use Carbon\Carbon;
use Elegantly\Forex\Facades\Forex;
$rates = Forex::rates(Carbon::create(2022, 4, 25), 'USD');
$usdToEur = $rates['EUR'];
Run the test suite with:
composer test
See the CHANGELOG for details on recent updates.
Contributions are welcome! Please read the CONTRIBUTING guide for details.
If you discover any security-related issues, please refer to our security policy.
This package is open-source software licensed under the MIT license.
Let me know if you'd like this version saved in a README.md
file or if you want badges for other integrations!