PHP code example of brightcreations / exchange-rates
1. Go to this page and download the library: Download brightcreations/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/ */
brightcreations / exchange-rates example snippets
use BrightCreations\ExchangeRates\Facades\ExchangeRate;
ExchangeRate::supportsHistoricalApiFetch(); // true when provider auto-fetches on historical miss
ExchangeRate::isSupportHistoricalExchangeRate(); // true when historical DB reads are available
use BrightCreations\ExchangeRates\Facades\ExchangeRate;
class CurrencyController extends Controller
{
public function getRates(string $currency = 'USD')
{
// Fetch from provider, store, and return current exchange rates
$rates = ExchangeRate::storeExchangeRates($currency);
return response()->json($rates);
}
}
use BrightCreations\ExchangeRates\Facades\HistoricalExchangeRate;
use Carbon\Carbon;
class HistoricalController extends Controller
{
public function getHistoricalRates(string $currency, string $date)
{
$dateTime = Carbon::parse($date);
$rates = HistoricalExchangeRate::getHistoricalExchangeRates($currency, $dateTime);
return response()->json($rates);
}
}
use BrightCreations\ExchangeRates\Facades\ExchangeRateRepository;
$rate = ExchangeRateRepository::getExchangeRate('USD', 'EUR');