PHP code example of dostrog / larate

1. Go to this page and download the library: Download dostrog/larate 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/ */

    

dostrog / larate example snippets


return [
    'default_base_currency' => 'RUB',
    'service' => [
        'RUB' => Dostrog\Larate\Services\RussianCentralBank::class,
        'UAH' => Dostrog\Larate\Services\NationalBankOfUkraine::class,
    ],
];

// instantiate from Laravel IoC for inject provider
// according to config it maybe RUB (converted) rates from Central Bank OF Russia
$provider = app()->make(Larate::class);
$pair = new CurrencyPair('RUB', 'USD');
$date = Carbon::parse('2020-01-16');
$rate = $provider->getExchangeRate($pair, $date);
$value = $rate->getValue(); // 61.4328

// ...or using factory method, i.e. for getting UAH (converted) rates from National Bank of Ukraine
$provider = Larate::createForBaseCurrency('UAH');
$pair = new CurrencyPair('UAH', 'USD');
$date = Carbon::parse('2020-01-16');
$rate = $provider->getExchangeRate($pair, $date);
$value = $rate->getValue(); // 23.9821

// ...or using Laravel's Facades
$rate = LarateFacade::getExchangeRate($pair, $date);
$value = $rate->getValue();
bash
php artisan vendor:publish --provider="Dostrog\Larate\Providers\LarateServiceProvider" --tag="config"