Skip to content

Laravel Currency

Currency conversion, exchange rates and money formatting for Laravel. Rates come from pluggable providers — Ukrainian banks (Monobank, PrivatBank, NBU) and international APIs (jsDelivr currency-api, ExchangeRatesAPI / frankfurter, CurrencyAPI, Fixer) — and are cached with a fallback for when the API is down.

  • Conversion with buy / sell / average rates
  • Seven built-in providers, switchable at runtime, plus your own via a small contract
  • Historical rates — convert at the rate of a past date
  • Base currency override — rates recalculated relative to any currency the provider knows
  • Caching with a long-term fallback cache and a CurrencyRateFetchFailed event for alerting
  • Formatting — symbol, precision, separators per currency
  • Global helpers, Blade directives and two Artisan commands
use Fomvasss\Currency\Facades\Currency;
Currency::convert(100, 'USD', 'UAH'); // 100 USD in UAH at the average rate
Currency::convert(100, 'USD', 'UAH', 'sell'); // at the bank's selling rate
Currency::getRate('EUR'); // UAH per 1 EUR
Currency::format(1234.5, 'USD'); // "$ 1,234.50"
Currency::useProvider('nbu')
->convertAt(100, 'USD', 'UAH', now()->subYear()); // rate as of a year ago
Terminal window
php artisan currency:rates --provider=nbu
php artisan currency:convert 100 usd eur --format

Getting started

  1. Installation
  2. Configuration

Usage

  1. Converting & rates
  2. Rate providers
  3. Base currency
  4. Historical rates
  5. Formatting & currencies
  6. Helpers & Blade
  7. Caching & failures
  8. Custom providers

Reference

  1. Currency facade
  2. Providers
  3. Contracts, events & manager
  4. Artisan commands

Upgrading