Skip to content

Configuration

All settings live in config/currency.php (publish it with php artisan vendor:publish --tag=currency-config).

KeyEnvDefaultDescription
default—'UAH'Base currency of the Currency facade: what getRate() and getRates() are expressed in. If it differs from the provider’s own base, rates are recalculated, see Base currency
default_providerCURRENCY_DEFAULT_PROVIDER'monobank'Provider used by the Currency facade: an alias from providers or a fully-qualified class name implementing RateProvider
providers—7 built-in aliasesMap of alias → class, used by useProvider(), setRateProvider() and currency:rates --provider
cache_ttlCURRENCY_CACHE_TTL3600Seconds a fetched set of current rates is cached
cache_ttl_fallbackCURRENCY_CACHE_TTL_FALLBACK86400Seconds the last successful rates are kept as a fallback for when the API fails
cache_ttl_emptyCURRENCY_CACHE_TTL_EMPTY60Seconds a failed fetch is cached before the next retry — empty rates, or fallback/static rates served instead
cache_ttl_historicalCURRENCY_CACHE_TTL_HISTORICALnullSeconds rates for a past date are cached; null or empty caches them forever. Today’s and future dates use cache_ttl
default_rate_typeCURRENCY_DEFAULT_RATE_TYPE'average'Rate type used when a method gets $rateType = null: buy, sell or average
default_precisionCURRENCY_DEFAULT_PRECISION2Decimal places for convert(), format() and getPrecision() when the currency has no own precision
exchange_rates_api_keyEXCHANGE_RATES_API_KEYnullKey for exchangeratesapi; without it the provider uses frankfurter.dev
currencyapi_keyCURRENCYAPI_KEYnullKey for currencyapi (required)
fixer_api_keyFIXER_API_KEYnullKey for fixer (required)
currencies—EUR, PLN, UAH, USDCurrencies known to your app, with formatting options
'default_provider' => env('CURRENCY_DEFAULT_PROVIDER', 'monobank'),
'providers' => [
'nbu' => \Fomvasss\Currency\RateProviders\NbuRateProvider::class,
'monobank' => \Fomvasss\Currency\RateProviders\MonobankRateProvider::class,
'privatbank' => \Fomvasss\Currency\RateProviders\PrivatbankRateProvider::class,
'jsdelivr' => \Fomvasss\Currency\RateProviders\JsDelivrProvider::class,
'exchangeratesapi' => \Fomvasss\Currency\RateProviders\ExchangeRatesApiProvider::class,
'currencyapi' => \Fomvasss\Currency\RateProviders\CurrencyApiProvider::class,
'fixer' => \Fomvasss\Currency\RateProviders\FixerProvider::class,
],

Add your own provider under any alias — see Custom providers. Provider classes are built through the service container, so constructor arguments can be configured with container bindings, see Rate providers.

'cache_ttl' => env('CURRENCY_CACHE_TTL', 3600),
'cache_ttl_fallback' => env('CURRENCY_CACHE_TTL_FALLBACK', 86400),
'cache_ttl_empty' => env('CURRENCY_CACHE_TTL_EMPTY', 60),
'cache_ttl_historical' => env('CURRENCY_CACHE_TTL_HISTORICAL'),

How the four interact — Caching & failures.

'default_rate_type' => env('CURRENCY_DEFAULT_RATE_TYPE', 'average'),
'default_precision' => env('CURRENCY_DEFAULT_PRECISION', 2),
  • buy — the bank’s buying rate (you sell foreign currency to the bank)
  • sell — the bank’s selling rate (you buy foreign currency from the bank)
  • average — (buy + sell) / 2

An invalid default_rate_type is not checked at boot; every call that falls back to it throws InvalidArgumentException: Invalid rate type.

'currencies' => [
'USD' => [
'code' => 'USD',
'title' => 'US Dollar',
'symbol' => '$',
'precision' => 2,
'thousandSeparator' => ',',
'decimalSeparator' => '.',
'symbolPlacement' => 'before',
],
// ...
],
FieldUsed byFallback when missing
codeinformational—
titlecurrency:rates --currency=XN/A
symbolformat(), currency_symbol(), @currencySymbolthe currency code
precisionformat(), convert() rounding, getPrecision()default_precision
thousandSeparatorformat(),
decimalSeparatorformat().
symbolPlacementformat(): before or afterbefore
activegetActiveCurrencies() — false excludes the currencytrue

The array key is what lookups use (getCurrencyConfig('usd') upper-cases the code and reads currencies.USD). The published config contains ~25 more currencies commented out — uncomment the ones you need.

The currencies list is independent of the provider: a currency doesn’t have to be listed here to be converted, and listing it doesn’t make the provider return a rate for it.

CURRENCY_DEFAULT_PROVIDER=monobank
CURRENCY_DEFAULT_RATE_TYPE=average
CURRENCY_DEFAULT_PRECISION=2
CURRENCY_CACHE_TTL=3600
CURRENCY_CACHE_TTL_FALLBACK=86400
CURRENCY_CACHE_TTL_EMPTY=60
# CURRENCY_CACHE_TTL_HISTORICAL=2592000
# key-based providers
EXCHANGE_RATES_API_KEY=
CURRENCYAPI_KEY=
FIXER_API_KEY=