Skip to content

Artisan commands

CommandDescription
currency:ratesShow the current (or historical) rates of a provider
currency:convertConvert an amount

Both use the currency service, so they respect default_provider and default (base currency) from config.

Terminal window
php artisan currency:rates
php artisan currency:rates --provider=nbu
php artisan currency:rates --currency=usd
php artisan currency:rates --provider=nbu --date=2024-01-15
php artisan currency:rates --refresh
OptionDescription
--provider=Config alias or class name (setRateProvider()); an invalid one prints Invalid provider: X and exits with 1
--currency=Show one currency as a property table (code, title and symbol from config, buy, sell, average)
--date=Historical rates for this date, parsed by Carbon::parse(). Exits with 1 if the provider doesn’t support historical rates
--refreshClear the provider’s current, fallback and historical cache before fetching

Without --currency it prints a table of all rates (buy, sell, average to 4 decimals) and the total count, or No rates available. when the provider returned nothing. Rates are relative to the base currency (default), recalculated if it differs from the provider’s base.

--currency for a code the provider doesn’t have prints an error but still exits with 0.

Terminal window
php artisan currency:convert 100 usd uah
php artisan currency:convert 100 usd eur --rate=sell --format
php artisan currency:convert 100 usd uah --date=2024-01-15
Argument / optionDescription
amountAmount, cast to float
from, toCurrency codes, case-insensitive
--rate=averagebuy, sell or average
--date=Use the historical rate for this date (convertAt()), parsed by Carbon::parse()
--formatPrint amounts with format() (symbol, separators)

Prints the source and converted amounts, the rate type, the date (with --date) and the rate of from. Errors (Conversion error: ...) exit with 1.