elegantly / laravel-forex
Forex for Laravel
Fund package maintenance!
Finller
Requires
- php: ^8.1
- illuminate/contracts: ^10.0||^11.0||^12.0
- saloonphp/cache-plugin: ^3.0
- saloonphp/laravel-plugin: ^3.0
- saloonphp/rate-limit-plugin: ^2.0
- saloonphp/saloon: ^3.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
README
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.
π Installation
Install via Composer:
composer require elegantly/laravel-forex
Publish the configuration file:
php artisan vendor:publish --tag="forex-config"
βοΈ Configuration
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'), ], ], ];
π¦ Usage
Get Latest Rates
use Elegantly\Forex\Facades\Forex; $rates = Forex::latest('USD'); $usdToEur = $rates['EUR'];
Get Historical Rates
use Carbon\Carbon; use Elegantly\Forex\Facades\Forex; $rates = Forex::rates(Carbon::create(2022, 4, 25), 'USD'); $usdToEur = $rates['EUR'];
β Testing
Run the test suite with:
composer test
π Changelog
See the CHANGELOG for details on recent updates.
π€ Contributing
Contributions are welcome! Please read the CONTRIBUTING guide for details.
π Security
If you discover any security-related issues, please refer to our security policy.
π Credits
π License
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!