Skip to content

ElegantEngineeringTech/laravel-forex

Repository files navigation

Laravel Forex

Latest Version on Packagist
Tests
Code Style
Total Downloads

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!

Sponsor this project

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages