PHP code example of finller / laravel-forex
1. Go to this page and download the library: Download finller/laravel-forex library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
finller / laravel-forex example snippets
use Elegantly\Forex\Integrations\ExchangeRateApiFree\ExchangeRateApiFreeConnector;
return [
'cache' => [
'enabled' => true,
'driver' => env('FOREX_CACHE_DRIVER', env('CACHE_STORE', env('CACHE_DRIVER', 'file'))),
'expiry_seconds' => 86_400, // 1 day
],
'rate_limit' => [
'enabled' => false,
'driver' => env('FOREX_RATE_LIMIT_DRIVER', env('CACHE_STORE', 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'];
use Elegantly\Forex\Facades\Forex;
use Brick\Money\Money;
$convertedMoney = Forex::convert(
money: Money::of(100, 'USD'),
currency: 'EUR',
);
$convertedMoney->__toString(); // (EUR) 88.84
bash
php artisan vendor:publish --tag="forex-config"