PHP code example of ashallendesign / laravel-exchange-rates
1. Go to this page and download the library: Download ashallendesign/laravel-exchange-rates 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/ */
ashallendesign / laravel-exchange-rates example snippets
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
$exchangeRates = app(ExchangeRate::class);
$exchangeRates->currencies();
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
$exchangeRates = app(ExchangeRate::class);
$result = $exchangeRates->exchangeRate('GBP', 'EUR');
// $result: 1.10086
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
$exchangeRates = app(ExchangeRate::class);
$result = $exchangeRates->exchangeRate('GBP', ['EUR', 'USD']);
// $result: [
// 'EUR' => 1.10086,
// 'USD' => 1.25622,
// ];
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
$exchangeRates = app(ExchangeRate::class);
$result = $exchangeRates->exchangeRateBetweenDateRange(
'GBP',
'EUR',
Carbon::now()->subWeek(),
Carbon::now()
);
// $result: [
// '2020-07-07' => 1.1092623405
// '2020-07-08' => 1.1120625424
// '2020-07-09' => 1.1153867604
// ];
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
$exchangeRates = app(ExchangeRate::class);
$result = $exchangeRates->exchangeRateBetweenDateRange(
'GBP',
['EUR', 'USD'],
Carbon::now()->subDays(3),
Carbon::now()
);
// $result: [
// '2020-07-07' => [
// 'EUR' => 1.1092623405,
// 'USD' => 1.2523571825,
// ],
// '2020-07-08' => [
// 'EUR' => 1.1120625424,
// 'USD' => 1.2550737853,
// ],
// '2020-07-09' => [
// 'EUR' => 1.1153867604,
// 'USD' => 1.2650716636,
// ],
// ];
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
$exchangeRates = app(ExchangeRate::class);
$result = $exchangeRates->convert(100, 'GBP', 'EUR', Carbon::now());
// $result: 110.15884906
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
$exchangeRates = app(ExchangeRate::class);
$result = $exchangeRates->convert(
100,
'GBP',
['EUR', 'USD'],
Carbon::now()
);
// $result: [
// 'EUR' => 110.15884906,
// 'USD' => 125.30569081
// ];
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
$exchangeRates = app(ExchangeRate::class);
$exchangeRates->convertBetweenDateRange(
100,
'GBP',
'EUR',
Carbon::now()->subDays(3),
Carbon::now()
);
// $result: [
// '2020-07-07' => 110.92623405,
// '2020-07-08' => 111.20625424,
// '2020-07-09' => 111.53867604,
// ];
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
$exchangeRates = app(ExchangeRate::class);
$result = $exchangeRates->exchangeRateBetweenDateRange(
'GBP',
['EUR', 'USD'],
Carbon::now()->subDays(3),
Carbon::now()
);
// $result: [
// '2020-07-07' => [
// 'EUR' => 110.92623405,
// 'USD' => 125.23571825,
// ],
// '2020-07-08' => [
// 'EUR' => 111.20625424,
// 'USD' => 125.50737853,
// ],
// '2020-07-09' => [
// 'EUR' => 111.53867604,
// 'USD' => 126.50716636,
// ],
// ];
use AshAllenDesign\LaravelExchangeRates\Facades\ExchangeRate;
ExchangeRate::currencies();
// Using the "ExchangeRate" class:
$exchangeRates = app(ExchangeRate::class);
$result = $exchangeRates->exchangeRate('GBP', ['EUR', 'USD']);
// Using the "ExchangeRate" facade:
ExchangeRate::exchangeRate('GBP', ['EUR', 'USD']);
// Using the "ExchangeRate" class:
$exchangeRates = app(ExchangeRate::class);
$result = $exchangeRates
->driver('exchange-rates-data-api')
->exchangeRate('GBP', ['EUR', 'USD']);
// Using the "ExchangeRate" facade:
ExchangeRate::driver('exchange-rates-data-api')
->exchangeRate('GBP', ['EUR', 'USD']);
use AshAllenDesign\LaravelExchangeRates\Rules\ValidCurrency;
use Illuminate\Support\Facades\Validator;
$formData = [
'currency' => 'GBP',
];
$rules = [
'currency' => new ValidCurrency(),
];
$validator = Validator::make($formData, $rules);
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
$exchangeRates = app(ExchangeRate::class);
$exchangeRates->shouldBustCache()
->convert(
100,
'GBP',
'EUR',
Carbon::now()
);
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
$exchangeRates = app(ExchangeRate::class);
$exchangeRates->shouldCache(false)
->convert(
100,
'GBP',
'EUR',
Carbon::now()
);
bash
php artisan vendor:publish --provider="AshAllenDesign\LaravelExchangeRates\Providers\ExchangeRatesProvider"