Weave Code
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

Exchanger Laravel Package

florianv/exchanger

PHP exchange-rate provider layer with 31 services behind one ExchangeRateService interface. Supports historical rates, PSR-16 caching, and chainable fallback across providers (commercial APIs, ECB, national banks, exchangerate.host) for fine-grained control.

View on GitHub
Deep Wiki
Context7

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

Frequently asked questions about Exchanger
How do I integrate florianv/exchanger into a Laravel project for currency conversion?
Start by installing the package via Composer (`composer require florianv/exchanger`) and register a service provider in `config/app.php`. Bind the `ExchangeRateService` to Laravel’s container using a `Chain` of providers (e.g., ECB, Fixer) and a PSR-16 cache adapter like `league/psr6-adapter-symfony-cache`. Use Laravel’s `.env` for API keys and inject the service into controllers or commands.
Which Laravel versions and PHP versions does florianv/exchanger support?
The package requires PHP 8.2+ and is compatible with Laravel 10+. For older Laravel versions (e.g., 9.x), ensure your dependencies (PSR-18 HTTP client, PSR-16 cache) align with Laravel’s ecosystem. Test thoroughly, as some providers may have stricter requirements.
Can I use florianv/exchanger with Laravel’s built-in cache instead of Redis?
Yes, Laravel’s cache (PSR-6) can be adapted to PSR-16 using `league/psr6-adapter-symfony-cache` or `spatie/laravel-cache`. Configure the adapter in your service provider to wrap Laravel’s cache store, then pass it to the `Exchanger` constructor. This avoids external dependencies while maintaining caching benefits.
How do I set up fallback providers in florianv/exchanger for reliability?
Use the `Chain` class to order providers by priority (e.g., free tiers first, paid APIs last). Configure the chain in your service provider: `$chain = new Chain([new Fixer($apiKey), new EuropeanCentralBank()])`. The chain automatically retries failed providers until one succeeds or all are exhausted, reducing single-point failures.
What’s the difference between florianv/exchanger and florianv/swap for Laravel?
Swap is a high-level wrapper built on Exchanger, offering a builder-style API with sensible defaults. Use Exchanger directly when you need granular control—like custom facades, middleware (e.g., retries), or framework-specific integrations. Swap is ideal for quick implementations; Exchanger is for advanced use cases.
How do I mock florianv/exchanger providers for unit testing in Laravel?
Use PHPUnit’s mock builder or Mockery to create a mock `ExchangeRateService` and inject it into your tested class. For the `Chain`, mock individual providers and configure the chain to return mock responses. Example: `$mockProvider = $this->createMock(ExchangeRateService::class); $mockProvider->method('getRate')->willReturn(1.2); $chain = new Chain([$mockProvider]);`
Are there any cost considerations when using paid APIs like Fixer or exchangerate.host?
Yes, commercial providers (e.g., Fixer) have usage limits and costs. Track API calls by logging requests in middleware or using Laravel’s `HttpClient` interceptors. Rotate API keys via `.env` and monitor quotas to avoid unexpected charges. The `Chain` helps distribute load across free/paid providers.
How do I handle historical exchange rates with florianv/exchanger?
Most providers support historical rates via their API endpoints (e.g., `getHistoricalRate($date)`). Configure the provider to include the date parameter, then cache responses with a TTL (e.g., 1 day) to avoid repeated API calls. Validate provider support for historical data before relying on it in production.
Can I add custom HTTP middleware (e.g., retries) to florianv/exchanger providers?
Yes, leverage Laravel’s HTTP client middleware by wrapping provider requests. For Guzzle, use `HttpClient::withOptions(['handler' => HandlerStack::create()])` to add middleware like retries or rate limiting. Inject the configured client into the provider’s constructor or use Laravel’s `app()` helper to resolve it dynamically.
What are the risks of using free exchange rate APIs, and how does florianv/exchanger mitigate them?
Free APIs often have rate limits, unreliable uptime, or limited currency pairs. Exchanger mitigates this with the `Chain` fallback system—if one provider fails, the next is tried. Monitor provider health via Laravel’s health checks or custom middleware. For critical apps, prioritize paid providers in the chain and set up alerts for failures.
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai