1. Go to this page and download the library: Download nurbekjummayev/cbu-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/ */
nurbekjummayev / cbu-currency example snippets
return [
// CBU API Base URL
'base_url' => env('CBU_BASE_URL', 'https://cbu.uz/ru/arkhiv-kursov-valyut/json'),
// Cache duration in minutes
'cache_duration' => env('CBU_CACHE_DURATION', 60),
// Default currency code
'default_currency' => env('CBU_DEFAULT_CURRENCY', 'USD'),
// Decimal places for the FINAL conversion result (default: 0 = no
// rounding, full computed precision). Internal calculations always run
// at full precision and are never rounded mid-calculation. Set a
// positive value or use ->scale(n) per call to round the final result
// half-up, or round the returned result yourself with ->round(n).
'scale' => env('CBU_SCALE', 0),
// Data source: 'database' or 'api'
'source' => env('CBU_SOURCE', 'database'),
// Enable/disable logging
'log_enabled' => env('CBU_LOG_ENABLED', true),
// API routes configuration
'routes' => [
'enabled' => env('CBU_ROUTES_ENABLED', true),
'prefix' => env('CBU_ROUTES_PREFIX', 'api/currency'),
'middleware' => ['api'],
],
];
// Specific date
$result = CbuCurrency::convert()
->from('USD')
->to('EUR')
->amount(100)
->date('2025-01-25')
->get();
// Today's date
$result = CbuCurrency::convert()
->from('USD')
->to('EUR')
->amount(100)
->today()
->get();
use Cbu\Currency\Enums\CurrencySource;
// Force API source
$result = CbuCurrency::convert()
->source(CurrencySource::API)
->from('USD')
->to('EUR')
->amount(100)
->get();
// Force database source
$result = CbuCurrency::convert()
->source(CurrencySource::DATABASE)
->from('USD')
->to('EUR')
->amount(100)
->get();
// Cache result for 60 minutes
$result = CbuCurrency::convert()
->from('USD')
->to('EUR')
->amount(100)
->cache(60)
->get();
use Cbu\Currency\Facades\CbuCurrency;
// Get single currency rate for today
$rate = CbuCurrency::rate('USD');
echo $rate->ccy; // "USD"
echo $rate->rate; // 12705.00
echo $rate->diff; // 15.25
echo $rate->date; // "2025-11-09"
// Get USD rate for specific date
$rate = CbuCurrency::rate('USD', '2025-01-25');
echo $rate->rate; // 12705.00
echo $rate->date; // "2025-01-25"
// Get all currencies rates for today
$rates = CbuCurrency::rate();
foreach ($rates as $rate) {
echo "{$rate->ccy}: {$rate->rate}\n";
}
// USD: 12705.00
// EUR: 13500.00
// RUB: 130.00
// Get all rates for specific date
$rates = CbuCurrency::rate(null, '2025-01-25');
foreach ($rates as $rate) {
echo "{$rate->ccy}: {$rate->rate} ({$rate->date})\n";
}
use Cbu\Currency\Facades\CbuCurrency;
// Get all currencies
$currencies = CbuCurrency::currencies();
foreach ($currencies as $currency) {
echo "{$currency->ccy} - {$currency->name_en}\n";
}
// USD - US Dollar
// EUR - Euro
// RUB - Russian Ruble
// Get array of currency codes
$codes = CbuCurrency::currencies()->pluck('ccy')->toArray();
// ['USD', 'EUR', 'RUB', 'GBP', 'JPY', ...]
use Cbu\Currency\Facades\CbuCurrency;
// Sync currencies list
CbuCurrency::sync('currencies');
// Sync today's rates
CbuCurrency::sync('rates');
// Sync rates for specific date
CbuCurrency::sync('rates', '2025-01-25');
// Sync both currencies and rates
CbuCurrency::sync('currencies');
CbuCurrency::sync('rates');
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected function schedule(Schedule $schedule)
{
// Fetch rates daily at 10:00 AM (after CBU updates)
$schedule->command('cbu:fetch-rates')
->dailyAt('10:00')
->onFailure(function () {
// Notify admin if sync fails
});
// Sync currencies every Monday at 9:00 AM
$schedule->command('cbu:sync-currencies')
->weekly()
->mondays()
->at('09:00');
}
}