PHPackages                             fomvasss/laravel-currency - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fomvasss/laravel-currency

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fomvasss/laravel-currency
=========================

Laravel package for working with multiple currencies, providing currency conversion, exchange rate management, and formatted output

2.5.1(1mo ago)3296—0%MITPHPPHP ^8.1CI failing

Since Nov 26Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/fomvasss/laravel-currency)[ Packagist](https://packagist.org/packages/fomvasss/laravel-currency)[ Fund](https://send.monobank.ua/jar/5xsqtHvVrY)[ Fund](https://ko-fi.com/fomvasss)[ RSS](/packages/fomvasss-laravel-currency/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (15)Versions (14)Used By (0)

Laravel Currency
================

[](#laravel-currency)

[![Laravel](https://camo.githubusercontent.com/aa78f8638e28f31998010a899234a303b8ec5927a3ccee4915c2131009b4c0cc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d392b2d726564)](https://laravel.com/)[![Latest Stable Version](https://camo.githubusercontent.com/560e75d334a104b1435a6eb20a3111fa5d85875859640fa7724119b1a4817be7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f6d76617373732f6c61726176656c2d63757272656e63792e737667)](https://packagist.org/packages/fomvasss/laravel-currency)[![Build Status](https://camo.githubusercontent.com/fdb801bdbd846c9f14d8264ddf2eebf38ff2733151aba5b0097eb15387d2c124/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f666f6d76617373732f6c61726176656c2d63757272656e63792e7376673f7374796c653d666f722d746865)](https://github.com/fomvasss/laravel-currency)[![Total Downloads](https://camo.githubusercontent.com/75399f6b69dc551e537e5c6f4d09b104849ec3beff0054766b53b0cd3cf9c1f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666f6d76617373732f6c61726176656c2d63757272656e63792e737667)](https://packagist.org/packages/fomvasss/laravel-currency)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

Support
-------

[](#support)

If this package is useful to you, consider supporting its development:

[![Monobank](https://camo.githubusercontent.com/f4ca1cf4fd0a99ddfed314cb8f65140d8e83e324bd7c1f8476c52fe4ee6b25fd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d4d6f6e6f62616e6b2d626c61636b)](https://send.monobank.ua/jar/5xsqtHvVrY)[![Ko-Fi](https://camo.githubusercontent.com/10764ec41c79959f08ccaf3e066c7a76c371961b1b1ff5b5f2a33aceef6e857a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d4b6f2d2d66692d4646354535423f6c6f676f3d6b6f2d6669266c6f676f436f6c6f723d7768697465)](https://ko-fi.com/fomvasss)[![USDT TRC20](https://camo.githubusercontent.com/214b4dc05bedda1c5129726b4450ef7f672ce6637865f8a8be83c03582bfdce8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d5553445425323054524332302d3236413137423f6c6f676f3d746574686572266c6f676f436f6c6f723d7768697465)](https://link.trustwallet.com/send?coin=195&address=THLgp6DxiAtbNHvgnKV56vk1L38UuUagKf&token_id=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t)

> USDT TRC20 address: `THLgp6DxiAtbNHvgnKV56vk1L38UuUagKf`

A Laravel package for currency conversion and exchange rate management with multiple rate providers.

Features
--------

[](#features)

- Currency conversion with buy / sell / average rates
- Multiple built-in rate providers (Monobank, PrivatBank, NBU, jsDelivr, ExchangeRatesAPI, CurrencyAPI, Fixer)
- Automatic caching of exchange rates with configurable TTL and fallback cache
- Dynamic base currency override with automatic rate recalculation
- Currency formatting with symbols, precision and locale separators
- Helper functions and Blade directives for use in views
- Custom provider support via a simple interface

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 9.x, 10.x, 11.x, 12.x, or 13.x

Installation
------------

[](#installation)

```
composer require fomvasss/laravel-currency
```

Publish the configuration file:

```
php artisan vendor:publish --tag=currency-config
```

Configuration
-------------

[](#configuration)

The published config file is located at `config/currency.php`.

### Available options

[](#available-options)

```
return [
    // Default base currency
    'default' => 'UAH',

    // Default rate provider alias (see 'providers' array)
    'default_provider' => env('CURRENCY_DEFAULT_PROVIDER', 'monobank'),

    // Available providers
    '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,
    ],

    // Primary rate cache TTL in seconds (default: 1 hour)
    'cache_ttl' => env('CURRENCY_CACHE_TTL', 3600),

    // Fallback cache TTL in seconds — used when primary API is unavailable (default: 1 day)
    'cache_ttl_fallback' => env('CURRENCY_CACHE_TTL_FALLBACK', 86400),

    // Default rate type: 'buy', 'sell', or 'average'
    'default_rate_type' => env('CURRENCY_DEFAULT_RATE_TYPE', 'average'),

    // Default decimal precision (can be overridden per currency)
    'default_precision' => env('CURRENCY_DEFAULT_PRECISION', 2),

    // API keys for paid/key-required providers
    'exchange_rates_api_key' => env('EXCHANGE_RATES_API_KEY', null),
    'currencyapi_key'        => env('CURRENCYAPI_KEY', null),
    'fixer_api_key'          => env('FIXER_API_KEY', null),

    // Active currencies with formatting options
    'currencies' => [
        'USD' => [
            'code'              => 'USD',
            'title'             => 'US Dollar',
            'symbol'            => '$',
            'precision'         => 2,
            'thousandSeparator' => ',',
            'decimalSeparator'  => '.',
            'symbolPlacement'   => 'before',
        ],
        // ... other currencies
    ],
];
```

### Environment Variables

[](#environment-variables)

```
CURRENCY_DEFAULT_PROVIDER=monobank
CURRENCY_DEFAULT_RATE_TYPE=average
CURRENCY_CACHE_TTL=3600
CURRENCY_CACHE_TTL_FALLBACK=86400
CURRENCY_DEFAULT_PRECISION=2

# For paid providers (optional)
EXCHANGE_RATES_API_KEY=your_key
CURRENCYAPI_KEY=your_key
FIXER_API_KEY=your_key
```

Rate Providers
--------------

[](#rate-providers)

AliasClassCurrenciesAPI KeyNotes`nbu``NbuRateProvider`30+NoNational Bank of Ukraine`monobank``MonobankRateProvider`MultipleNoMonobank API`privatbank``PrivatbankRateProvider`EUR, USD onlyNoPrivatBank API limitation`jsdelivr``JsDelivrProvider`150+NoFree CDN, updated daily`exchangeratesapi``ExchangeRatesApiProvider`MultipleYes`currencyapi``CurrencyApiProvider`MultipleYes (300 req/month free)`fixer``FixerProvider`MultipleYes (100 req/month free)Basic Usage
-----------

[](#basic-usage)

```
use Fomvasss\Currency\Facades\Currency;

// Convert currencies
$euros = Currency::convert(100, 'USD', 'EUR');

// Get exchange rate
$usdRate = Currency::getRate('USD');           // average by default
$buyRate  = Currency::getRate('USD', 'buy');
$sellRate = Currency::getRate('USD', 'sell');

// Get all rates
$allRates = Currency::getRates();              // average
$allRates = Currency::getRates('all');         // ['USD' => ['buy' => ..., 'sell' => ...], ...]

// Format currency
$formatted = Currency::format(1234.56, 'USD'); // $ 1,234.56
$noSymbol  = Currency::format(1234.56, 'USD', false); // 1,234.56
```

Switching Rate Providers
------------------------

[](#switching-rate-providers)

```
// Switch by alias (recommended)
Currency::useProvider('nbu');
Currency::useProvider('monobank');
Currency::useProvider('jsdelivr');

// Switch via setRateProvider — accepts alias, class name, or instance
Currency::setRateProvider('nbu');
Currency::setRateProvider(\Fomvasss\Currency\RateProviders\NbuRateProvider::class);
Currency::setRateProvider(new NbuRateProvider());

$rate = Currency::getRate('USD');
```

Base Currency
-------------

[](#base-currency)

```
// Get current base currency
$base = Currency::getBaseCurrency(); // 'UAH' (from config)

// Override base currency at runtime
// All rates returned by getRate() and getRates() are automatically recalculated
Currency::setBaseCurrency('USD');

$rates = Currency::getRates();
// Now returns rates relative to USD: ['EUR' => 0.92, 'UAH' => 41.5, ...]
// USD itself is NOT in the array (it is the base, rate = 1.0)

// Convert after changing base
$amount = Currency::convert(100, 'EUR', 'GBP');
```

Checking Provider Capabilities
------------------------------

[](#checking-provider-capabilities)

```
$currencies = Currency::getSupportedCurrencies();      // ['USD', 'EUR', ...]
$count      = Currency::getSupportedCurrenciesCount(); // e.g. 150 for jsdelivr

if (Currency::isSupported('JPY')) {
    $rate = Currency::getRate('JPY');
}
```

Active Currencies (from config)
-------------------------------

[](#active-currencies-from-config)

```
$currencies = Currency::getActiveCurrencies();     // full config array
$codes      = Currency::getActiveCurrencyCodes();  // ['UAH', 'USD', 'EUR', ...]
$allConfig  = Currency::getAllCurrencies();         // alias for getActiveCurrencies()

$usdConfig  = Currency::getCurrencyConfig('USD');  // ['symbol' => '$', 'precision' => 2, ...]
$precision  = Currency::getPrecision('USD');        // 2
```

Cache Management
----------------

[](#cache-management)

```
// Clear cached rates for the current provider
Currency::clearCache();
```

Fallback cache stores the last successful rates and is used automatically when the primary API is unavailable. Configure its TTL via `cache_ttl_fallback` or the `CURRENCY_CACHE_TTL_FALLBACK` env variable.

Helper Functions
----------------

[](#helper-functions)

Global PHP helpers are available without importing any class:

```
// Convert amount
$result = currency_convert(100, 'USD', 'EUR');
$result = currency_convert(100, 'USD', 'EUR', 'sell');

// Format with symbol
$output = currency_format(1234.56, 'USD');          // $ 1,234.56
$output = currency_format(1234.56, 'USD', false);   // 1,234.56

// Get rate
$rate = currency_rate('USD');           // average
$rate = currency_rate('USD', 'buy');

// Get symbol
$symbol = currency_symbol('USD'); // '$'
```

Blade Directives
----------------

[](#blade-directives)

```
{{-- Convert and output --}}
@currency(100, 'USD', 'EUR')

{{-- Format with symbol --}}
@currencyFormat(1234.56, 'USD')

{{-- Output exchange rate --}}
@currencyRate('USD')

{{-- Output symbol --}}
@currencySymbol('USD')
```

Event Handling
--------------

[](#event-handling)

The package dispatches a `CurrencyRateFetchFailed` event when an API call fails.

```
// app/Listeners/HandleCurrencyRateFailure.php
namespace App\Listeners;

use Fomvasss\Currency\Events\CurrencyRateFetchFailed;
use Illuminate\Support\Facades\Log;

class HandleCurrencyRateFailure
{
    public function handle(CurrencyRateFetchFailed $event): void
    {
        Log::error('Currency API failed', [
            'provider'      => $event->providerClass,
            'error'         => $event->errorMessage,
            'using_fallback' => $event->usingFallback,
        ]);
    }
}
```

Register in `EventServiceProvider`:

```
use Fomvasss\Currency\Events\CurrencyRateFetchFailed;
use App\Listeners\HandleCurrencyRateFailure;

protected $listen = [
    CurrencyRateFetchFailed::class => [
        HandleCurrencyRateFailure::class,
    ],
];
```

**Event properties:**

PropertyTypeDescription`$providerClass`stringClass name of the failed provider`$errorMessage`stringError description`$usingFallback`boolWhether fallback cache is being used`$fallbackRates`arrayFallback rates (if available)Fallback Strategy
-----------------

[](#fallback-strategy)

Use `jsdelivr` as a free fallback when primary APIs are unavailable:

```
try {
    Currency::useProvider('monobank');
    $rate = Currency::getRate('USD');
} catch (\Exception $e) {
    Currency::useProvider('jsdelivr'); // free, 150+ currencies, no rate limits
    $rate = Currency::getRate('USD');
}
```

Custom Providers
----------------

[](#custom-providers)

You can implement your own rate provider by creating a class that extends `AbstractRateProvider` or implements the `RateProvider` contract directly.

See the full guide with examples (API keys, multi-source fallback, mock for tests): [CUSTOM\_PROVIDERS.md](CUSTOM_PROVIDERS.md).

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE.md) for details.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance92

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~197 days

Recently: every ~6 days

Total

13

Last Release

38d ago

Major Versions

1.x-dev → 2.0.02026-01-21

PHP version history (2 changes)2.0.0PHP ^8.0

2.1.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4f99b460639e7d6871597882226b1e0d9e3055992eac8b22bfcd4f90fbdac95c?d=identicon)[fomvasss](/maintainers/fomvasss)

---

Top Contributors

[![fomvasss](https://avatars.githubusercontent.com/u/19834478?v=4)](https://github.com/fomvasss "fomvasss (16 commits)")[![RomanITS](https://avatars.githubusercontent.com/u/107628529?v=4)](https://github.com/RomanITS "RomanITS (2 commits)")

---

Tags

laravelmoneycurrencyconvertRateexchangecoinprivatbankmonobank

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fomvasss-laravel-currency/health.svg)

```
[![Health](https://phpackages.com/badges/fomvasss-laravel-currency/health.svg)](https://phpackages.com/packages/fomvasss-laravel-currency)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[toin0u/geocoder-laravel

Geocoder Service Provider for Laravel

7615.4M17](/packages/toin0u-geocoder-laravel)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.0M69](/packages/spatie-laravel-responsecache)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k91.9k1](/packages/mike-bronner-laravel-model-caching)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
