PHPackages                             florianv/laravel-swap - 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. florianv/laravel-swap

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

florianv/laravel-swap
=====================

Drop-in Laravel currency conversion: auto-discovered service provider, facade, and config. Multi-provider exchange rates.

2.4.1(1mo ago)3402.2M—1.6%492MITPHPPHP ^8.2CI passing

Since Jun 10Pushed 2w ago14 watchersCompare

[ Source](https://github.com/florianv/laravel-swap)[ Packagist](https://packagist.org/packages/florianv/laravel-swap)[ Docs](https://github.com/florianv/laravel-swap)[ RSS](/packages/florianv-laravel-swap/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (20)Versions (24)Used By (2)

Laravel Swap
============

[](#laravel-swap)

[![Tests](https://github.com/florianv/laravel-swap/actions/workflows/tests.yml/badge.svg)](https://github.com/florianv/laravel-swap/actions/workflows/tests.yml)[![Psalm](https://github.com/florianv/laravel-swap/actions/workflows/psalm.yml/badge.svg)](https://github.com/florianv/laravel-swap/actions/workflows/psalm.yml)[![Total Downloads](https://camo.githubusercontent.com/5b1edec1be0de53be65e1a93b3a34da132fd5be839d3ff0ea2a553bc3734d4fc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666c6f7269616e762f6c61726176656c2d737761702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/florianv/laravel-swap)[![Version](https://camo.githubusercontent.com/559537999e949ac5db42ad9bc20b98db735a41af9523078c7552f30fa6b73d75/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666c6f7269616e762f6c61726176656c2d737761702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/florianv/laravel-swap)

> *Drop-in currency conversion for Laravel and Lumen. Auto-discovered service provider, facade, and config. Maintained since 2014.*

   [ ![fastFOREX](https://camo.githubusercontent.com/01374173153db590b0bf73ec4f33df21d77996d1fa3c26f1dffe6462029f85fa/68747470733a2f2f636f6e736f6c652e66617374666f7265782e696f2f696d672f66617374666f7265782f6c6f676f2d626b2d316b2e737667) ](https://www.fastforex.io)   **Sponsored by [fastFOREX](https://www.fastforex.io).** Real-time JSON API, 160+ currencies, 55+ years of history, 500+ cryptocurrencies. **Free tier**; paid plans from $18/month. [**→ Get a free fastFOREX API key**](https://www.fastforex.io)  **Install, publish the config, and call `Swap::latest('EUR/USD')` from anywhere. No service container wiring, no boilerplate, no manual cache plumbing.**

Laravel Swap is a drop-in package for **Laravel currency conversion**. The service provider is auto-discovered in Laravel 5.5+; configuration publishes to `config/swap.php`; rates are cached through the Laravel cache store you already have. Lumen is supported.

💡 What is Laravel Swap?
-----------------------

[](#-what-is-laravel-swap)

- The Laravel application of [Swap](https://github.com/florianv/swap), the PHP currency conversion library.
- A service provider (`Swap\Laravel\SwapServiceProvider`) and a `Swap` facade, auto-discovered in Laravel 5.5+.
- Configuration published to `config/swap.php`.
- Rates cached through any Laravel cache store you already have.
- Lumen support with a few extra lines in `bootstrap/app.php`.

📦 Installation
--------------

[](#-installation)

Laravel Swap requires PHP 8.2 or newer.

```
composer require florianv/laravel-swap symfony/http-client nyholm/psr7
```

Auto-discovery wires the service provider and the `Swap` facade in Laravel 5.5+. For Lumen or older Laravel versions, see [Setup](doc/readme.md#-setup) in the documentation.

⚡ Quickstart
------------

[](#-quickstart)

The package ships a default config that pre-wires **[fastFOREX](https://www.fastforex.io)** (the project's sponsor) as the primary provider, with the European Central Bank as a free fallback. [Grab a free API key](https://www.fastforex.io) and add it to your `.env`:

```
SWAP_FASTFOREX_KEY=your_key_here
```

That's it. Without the env var, fastFOREX is skipped and the chain falls back to the European Central Bank, so the package still works out of the box without any key (EUR-base only).

To customize providers, options, or the cache store, publish the config:

```
php artisan vendor:publish --provider="Swap\Laravel\SwapServiceProvider"
```

Then call the facade from anywhere in the app:

```
use Swap;

// EUR → USD exchange rate
$rate = Swap::latest('EUR/USD');

$rate->getValue();                 // e.g. 1.0823 (a float)
$rate->getDate()->format('Y-m-d'); // e.g. 2026-04-29
$rate->getProviderName();          // 'fastforex'

// Convert an amount using the returned rate
$amountInEUR = 100.00;
$amountInUSD = $amountInEUR * $rate->getValue();

// Historical rate
$rate = Swap::historical('EUR/USD', \Carbon\Carbon::now()->subDays(15));
```

Providers are tried in declaration order. If a provider does not support the requested currency pair, it is skipped silently. If a provider throws an error, the next provider is tried. If every provider fails, a `ChainException` is thrown with all collected errors.

💾 Caching
---------

[](#-caching)

Set `cache` in `config/swap.php` to any Laravel cache store name:

```
// config/swap.php
'options' => [
    'cache_ttl' => 3600,
],
'cache' => 'redis', // any Laravel cache store: file, redis, database, ...
```

Per-query overrides:

```
Swap::latest('EUR/USD', ['cache' => false]);
Swap::latest('EUR/USD', ['cache_ttl' => 60]);
```

See the [documentation](doc/readme.md#-caching) for the full reference, including cache key prefixes and PSR-6 limitations.

📊 Providers
-----------

[](#-providers)

Laravel Swap supports the 30+ exchange rate providers from the underlying [Swap](https://github.com/florianv/swap) library. Pass the **identifier** as the key under `services` in `config/swap.php`.

### Commercial providers (require an API key)

[](#commercial-providers-require-an-api-key)

ServiceIdentifierBaseQuoteHistorical⭐ **[fastFOREX](https://www.fastforex.io)****`fastforex`****\*****\*****Yes**AbstractAPI`abstract_api`\*\*Yescoinlayer`coin_layer`\* (crypto)\*YesCryptonator`cryptonator`\* (crypto)\* (crypto)NoCurrency Converter API`currency_converter`\*\*YesCurrency Data (APILayer)`apilayer_currency_data`USD (free), \* (paid)\*YesCurrencyDataFeed`currency_data_feed`\*\*Nocurrencylayer (direct)`currency_layer`USD (free), \* (paid)\*YesExchange Rates Data (APILayer)`apilayer_exchange_rates_data`USD (free), \* (paid)\*Yesexchangerate.host`exchangeratehost`\*\*Yesexchangeratesapi (direct)`exchange_rates_api`USD (free), \* (paid)\*YesFixer (APILayer)`apilayer_fixer`EUR (free), \* (paid)\*YesFixer (direct)`fixer`EUR (free), \* (paid)\*Yes1Forge`forge`\*\*NoOpen Exchange Rates`open_exchange_rates`USD (free), \* (paid)\*YesUniRateAPI`unirate_api`\*\*YesWebserviceX`webservicex`\*\*NoxChangeApi.com`xchangeapi`\*\*YesXignite`xignite`\*\*Yes### Public providers (no API key required)

[](#public-providers-no-api-key-required)

ServiceIdentifierBaseQuoteHistoricalBulgarian National Bank`bulgarian_national_bank`\*BGNYesCentral Bank of the Czech Republic`central_bank_of_czech_republic`\*CZKYesCentral Bank of the Republic of Turkey`central_bank_of_republic_turkey`\*TRYYesCentral Bank of the Republic of Uzbekistan`central_bank_of_republic_uzbekistan`\*UZSYesEuropean Central Bank`european_central_bank`EUR\*YesNational Bank of Georgia`national_bank_of_georgia`\*GELYesNational Bank of Romania`national_bank_of_romania`(limited list)(limited list)YesNational Bank of the Republic of Belarus`national_bank_of_republic_belarus`\*BYNYesNational Bank of Ukraine`national_bank_of_ukraine`\*UAHYesRussian Central Bank`russian_central_bank`\*RUBYesThe per-provider option names (`api_key` vs `access_key` vs `app_id`, optional flags) are documented in [Provider configuration](doc/readme.md#-provider-configuration).

🎯 When should you use Laravel Swap?
-----------------------------------

[](#-when-should-you-use-laravel-swap)

- Use Laravel Swap when you need exchange rates inside a Laravel or Lumen application: localized prices, invoice totals, multi-currency reporting, historical FX data.
- You do not need to install [Swap](https://github.com/florianv/swap) separately. It is pulled in as a dependency, and Laravel Swap exposes it through Laravel's service container, facade, and cache store.

🛠 Common use cases
------------------

[](#-common-use-cases)

- Display localized prices in multi-currency Laravel storefronts.
- Compute invoice totals across currencies in a Laravel or Lumen API.
- Reconcile multi-currency ledgers using historical rates.
- Power internal FX dashboards with rate history.
- Build currency conversion infrastructure for Laravel-based fintech and ERP applications.

🧭 Which package should I use?
-----------------------------

[](#-which-package-should-i-use)

The Swap ecosystem is a layered toolkit for currency conversion in PHP:

- [**Swap**](https://github.com/florianv/swap). The easy-to-use, high-level API for plain PHP.
- [**Exchanger**](https://github.com/florianv/exchanger). Lower-level, more granular alternative; direct access to provider implementations.
- [**Laravel Swap**](https://github.com/florianv/laravel-swap). Laravel application of Swap (this package).
- [**Symfony Swap**](https://github.com/florianv/symfony-swap). Symfony integration of Swap.

All four packages are MIT-licensed and require PHP 8.2 or newer.

📚 Documentation
---------------

[](#-documentation)

The full documentation, with Lumen setup, per-provider configuration, custom service registration, and FAQ, is in [`doc/readme.md`](doc/readme.md).

🙌 Contributing
--------------

[](#-contributing)

Issues and pull requests are welcome. Please see the existing [issues](https://github.com/florianv/laravel-swap/issues) before opening a new one.

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [LICENSE](https://github.com/florianv/laravel-swap/blob/master/LICENSE) for more information.

👏 Credits
---------

[](#-credits)

- [Florian Voutzinos](https://github.com/florianv)
- [All contributors](https://github.com/florianv/laravel-swap/contributors)

###  Health Score

71

—

ExcellentBetter than 100% of packages

Maintenance93

Actively maintained with recent releases

Popularity61

Solid adoption and visibility

Community29

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 71.3% 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 ~221 days

Recently: every ~602 days

Total

19

Last Release

50d ago

Major Versions

0.x-dev → 1.0.02016-10-09

1.x-dev → 2.0.02019-02-12

PHP version history (5 changes)v0.1.0PHP &gt;=5.5.9

1.0.0PHP ^5.5|^7.0

2.0.0PHP ^7.1.3

2.3.0PHP ^7.1.3 || ^8.0

2.4.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1586668?v=4)[Florian Voutzinos](/maintainers/florianv)[@florianv](https://github.com/florianv)

---

Top Contributors

[![florianv](https://avatars.githubusercontent.com/u/1586668?v=4)](https://github.com/florianv "florianv (87 commits)")[![alies-dev](https://avatars.githubusercontent.com/u/5278175?v=4)](https://github.com/alies-dev "alies-dev (22 commits)")[![kslimani](https://avatars.githubusercontent.com/u/1758996?v=4)](https://github.com/kslimani "kslimani (7 commits)")[![denlapaev](https://avatars.githubusercontent.com/u/3096564?v=4)](https://github.com/denlapaev "denlapaev (1 commits)")[![arjanwestdorp](https://avatars.githubusercontent.com/u/7716654?v=4)](https://github.com/arjanwestdorp "arjanwestdorp (1 commits)")[![mohammad6006](https://avatars.githubusercontent.com/u/553379?v=4)](https://github.com/mohammad6006 "mohammad6006 (1 commits)")[![Naoray](https://avatars.githubusercontent.com/u/10154100?v=4)](https://github.com/Naoray "Naoray (1 commits)")[![rob-browncc](https://avatars.githubusercontent.com/u/199503049?v=4)](https://github.com/rob-browncc "rob-browncc (1 commits)")[![simplenotezy](https://avatars.githubusercontent.com/u/3786627?v=4)](https://github.com/simplenotezy "simplenotezy (1 commits)")

---

Tags

currency-conversionexchange-rate-apiexchange-rateslaravellumenphpswapphplaravelmoneylumenexchange ratescurrency conversionswapexchange-rate-api

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/florianv-laravel-swap/health.svg)

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

###  Alternatives

[florianv/exchanger

PHP exchange rate provider layer for currency conversion: 30+ services, chain fallback, and caching.

1865.0M20](/packages/florianv-exchanger)[kra8/laravel-snowflake

Snowflake for Laravel and Lumen.

192453.6k9](/packages/kra8-laravel-snowflake)[wujunze/money-wrapper

MoneyPHP Wrapper

103.8k](/packages/wujunze-money-wrapper)

PHPackages © 2026

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