1. Go to this page and download the library: Download stichoza/nbg-currency 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/ */
$usd = NbgCurrency::get('usd'); // Currency object (Stichoza\NbgCurrency\Data\Currency)
$usd->code; // USD
$usd->rate; // 2.7112
$usd->name; // აშშ დოლარი
$usd->diff; // -0.0065
$usd->date; // Carbon object of date: 2022-12-01 17:45:12
$usd->validFrom; // Carbon object since when the rate is valid: 2022-12-02 00:00:00
$usd->change; // Currency rate change. -1 if decreased, 0 if unchanged and 1 if increased.
// Using methods available on Carbon objects
$usd->date->format('j F Y'); // 1 December 2022
$usd->date->diffForHumans(); // 3 days ago
$usd->validFrom->isPast(); // true
// Additional methods
$usd->increased(); // Returns true if rate has increased, false otherwise.
$usd->decreased(); // Returns true if rate has decreased, false otherwise.
$usd->unchanged(); // Returns true if rate hasn't changed, false otherwise.
// The changeString() method returns first parameter if rate was increased, second string if there was
// no change and third string if the rate went up. Useful for CSS classes, font icons, etc.
$class = $usd->changeString('text-red', 'text-gray', 'text-green');
$icon = $usd->changeString('fa-arrow-down', 'fa-circle', 'fa-arrow-down');
$currencies = NbgCurrency::date('3 days ago');
$currencies = NbgCurrency::date(Carbon::now()->startOfMonth(), 'en');
$currencies->date; // Carbon object of date
$currencies->get('usd'); // Returns Currency object for USD
$currencies->has('eur'); // True if EUR currency is contained in $currencies collection
$currencies->count(); // Count of Currency objects in collection
$currencies->get('usd')->rate; // Currency rate of USD
$currencies->get('eur')->date->diffForHumans(); // 10 days ago
// Next 3 method calls will result in 1 HTTP request in total.
NbgCurrency::rate('usd');
NbgCurrency::rate('eur');
NbgCurrency::rate('gbp');
// Next 3 method calls will result in 3 HTTP requests in total.
NbgGurrency::rate('usd', '2022-10-10');
NbgGurrency::rate('eur', '2022-11-11', 'en');
NbgGurrency::rate('gbp', '2022-11-11');
// Next 3 method calls will result in 2 HTTP request in total.
NbgGurrency::rate('usd', '2022-11-11');
NbgGurrency::rate('eur', '2022-11-11');
NbgGurrency::rate('gbp', '2022-11-11', 'en');
NbgCurrency::disableCaching(); // Disable caching, also removes data stored in the property.
NbgCurrency::enableCaching(); // Enables caching in class property.