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
Laravel Swap

Laravel Swap Laravel Package

florianv/laravel-swap

Laravel Swap lets you convert currencies and fetch exchange rates in Laravel apps. It wraps the Swap PHP library, supporting multiple rate providers, caching, and simple configuration for reliable currency conversion.

View on GitHub
Deep Wiki
Context7

Laravel Swap integrates the Swap currency exchange library into Laravel, offering a clean facade for fetching exchange rates and converting currencies. It ships with a service provider and publishable configuration, so you can plug in a provider and start converting in minutes.

  • Convert between currencies with up-to-date rates
  • Support for many providers (Fixer, currencylayer, exchangerate.host, and more)
  • Built-in caching to reduce API calls and improve performance
  • Simple Swap:: facade and config-driven setup
  • Extensible with custom providers and exchange-rate services
Frequently asked questions about Laravel Swap
What is florianv/laravel-swap and what does it actually do?
It is a thin Laravel integration layer over the florianv/swap currency exchange library. It provides an auto-discovered service provider with container bindings, a Swap facade, and a publishable config file. All the actual rate fetching and conversion logic lives in the underlying Swap library, so treat it as a convenience binding rather than a full FX platform.
How do I install laravel-swap and get my first currency conversion working?
Run composer require florianv/laravel-swap and Laravel package auto-discovery registers the service provider and facade for you. Publish the config with php artisan vendor:publish, then add your provider credentials such as API keys to your .env file. After that you can call the Swap facade to fetch rates or convert between currencies, typically within minutes of starting.
Which exchange rate providers does laravel-swap support?
It supports the providers available in the underlying Swap library, which include services like Fixer, currencylayer, and the European Central Bank. You configure one or more providers in the published config file, and the package can fall back to a secondary provider when the primary fails. Each provider has its own API key requirements, quotas, and rate limits, so check the specific provider you plan to use.
Which Laravel and PHP versions are supported by laravel-swap?
Supported versions are defined by the package's Composer constraints, so always check the composer.json of the exact release you install. Verify the constraint against your application's PHP and Laravel versions before committing. Because the package is a thin integration over florianv/swap, the upstream library's constraints also apply. Pin a specific version and confirm compatibility in a non-production spike first.
How does caching work for exchange rates in laravel-swap?
The package uses Laravel's cache system to store fetched rates, with cache behavior configured in the published config file. You should set a TTL that matches your accuracy requirements, since the package returns whatever the provider returned at fetch time. Make sure your cache driver works in your environment, whether that is Redis, file, or array, and check psr/simple-cache version alignment with your existing dependencies.
Does laravel-swap handle rounding and monetary precision?
No, the package does not enforce any rounding or monetary policy. It returns raw converted values, so rounding rules, base-currency conventions, and presentation formatting are entirely your responsibility. Wrap conversions in your own service and apply a single, tested rounding policy there, because a rounding bug in this layer becomes a financial-correctness bug downstream.
Should I call the Swap facade directly from my application code?
It is better to avoid calling the facade directly from domain code. Define a narrow internal interface such as CurrencyConverter and bind a SwapCurrencyConverter implementation in a service provider. This keeps the vendor surface isolated to one adapter, gives you a single choke point for rounding, caching, and telemetry, and makes a future provider or library swap a one-file change.
Can laravel-swap provide historical exchange rates or time-series data?
The package is designed for point-in-time currency conversion, not historical rate storage or time-series analysis. It returns current rates from the configured provider, and it is explicitly not an FX treasury or rate ledger. If you need audit, reconciliation, or lookback rates, you must persist rates yourself in your own database and query them from there.
What are the main risks of using laravel-swap in production?
The biggest risk is provider churn: every exchange rate provider has its own API key, quota, rate limits, and deprecation history, and the package can only return what the provider gives it. Rate accuracy and staleness are contractual with the provider, not guaranteed by the package. The project is also MIT-licensed with a single primary maintainer, so assign an internal owner and pin the version to reduce supply-chain risk.
How should I test currency conversion in a Laravel app using laravel-swap?
Do not hit live provider APIs in your test suite. Instead, bind a fake implementation of your own CurrencyConverter interface in the test container, or configure a stub provider and seed cached rates. Since the facade is only a thin wrapper, testing against your internal interface keeps tests fast and deterministic. Reserve live provider calls for a non-production spike where you validate returned rates against an independent reference.
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