Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Swap Laravel Package

florianv/swap

Swap is an easy-to-use PHP currency conversion library that retrieves exchange rates from 30+ providers behind a single API, with PSR-16 caching, historical rates, and automatic provider fallback. PHP 8.2+, maintained since 2014.

View on GitHub
Deep Wiki
Context7

PHP currency conversion library for retrieving exchange rates from 30 providers, with caching and fallback. Maintained since 2014.

Frequently asked questions about Swap
How do I install florianv/swap in a Laravel application?
Run composer require florianv/swap symfony/http-client nyholm/psr7. Swap needs a PSR-18 HTTP client and PSR-17 request factories, which php-http/discovery resolves automatically; symfony/http-client and nyholm/psr7 are the documented defaults, but Guzzle and other PSR-18/PSR-17 implementations work too. The library requires PHP 8.2 or newer.
Does florianv/swap work with Laravel, or do I need the laravel-swap package?
Both work. Swap itself is framework-agnostic and has no bootstrapping, persistence, or global state, so it binds cleanly into Laravel's service container as a singleton built from a config array. florianv/laravel-swap is a separate first-party wrapper that removes glue code but adds a second dependency whose PHP and Laravel version cadence you must validate independently.
Which PHP and Laravel versions does Swap support?
Swap requires PHP 8.2 or newer. Because it is framework-agnostic, it does not pin a Laravel version, so support depends on whether your Laravel release runs on PHP 8.2+. That platform floor can block older estates or a legacy Laravel upgrade path, so confirm your runtime before adopting.
How do I cache exchange rates with Swap in Laravel?
Swap caches results through any PSR-16 SimpleCache implementation, passed in when you build the Swap instance. You can bridge Laravel's cache repository to PSR-16 or point the library at a dedicated store. Caching is what makes free public providers such as the ECB practical in production and keeps paid-provider request volume, and therefore spend, under control.
How does the provider fallback chain work in Swap, and why is my converted rate different from expected?
Swap tries providers in the configured order; when a provider errors, the next one in the chain is tried. A provider that does not support a given currency pair is skipped silently, so no exception is raised. That means a fallback can return a rate with different date granularity or a different provider's spread, so log getProviderName() and getDate() alongside every rate to keep conversions auditable.
Can I add a custom exchange rate provider to Swap?
Yes. The ExchangeRateService interface is a first-class extension point, so you can implement an internal treasury feed, a contracted bank API, or a cached database table and register it without forking the library. This escape hatch lowers lock-in considerably, since Swap is a convenience layer over HTTP and JSON rather than a data moat.
Does Swap support historical exchange rates?
Yes, Swap exposes historical rates in addition to the latest rate through the same provider interface. Coverage and granularity depend on the provider you choose: the ECB, for example, publishes daily EUR-based reference rates, while commercial APIs offer far deeper history. Swap does not persist history for you, so if you need immutable rates for audit or dispute resolution, store them in your own database at fetch time.
How do I avoid floating point rounding errors when converting currency with Swap?
ExchangeRate::getValue() returns a float, so multiplying that by a monetary amount invites rounding drift. For invoicing, ledger reconciliation, or tax-inclusive pricing, convert into a decimal or moneyphp/money value object and enforce a documented rounding mode before the rate touches money paths. moneyphp/money integration is available through SwapExchange, which keeps the arithmetic in integer minor units.
Is florianv/swap actively maintained and safe to use in production?
The project has been maintained since 2014 with CI covering tests and Psalm static analysis, and releases as recent as 2026 are a strong signal. It is still a small-maintainer project, so verify Packagist download trends, issue responsiveness, and release cadence yourself rather than trusting aggregate scores. Also treat provider selection as a separate procurement decision: each commercial provider has its own pricing, rate limits, and redistribution terms.
What are the alternatives to florianv/swap for currency conversion in Laravel?
You can call a single provider's JSON API directly, use moneyphp/money with its own exchanger, or adopt the first-party florianv/laravel-swap wrapper if you want Laravel-specific configuration out of the box. Swap's differentiator is breadth: 30+ providers behind one interface with caching, historical rates, and fallback built in. For apps converting in a single currency pair with low volume, a direct HTTP call plus cache may be simpler than any library.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo