ihangan/laravel-moldova-exchange-rates
Composer 安装命令:
composer require ihangan/laravel-moldova-exchange-rates
包简介
Official BNM (National Bank of Moldova) exchange rates for Laravel: fetch, store and convert, on a schedule.
README 文档
README
BNM exchange rates for Laravel
Pulls the official exchange rates published by the National Bank of Moldova (BNM), stores them, and lets you read or convert them. Rates come straight from the bank's public XML feed, normalised to MDL per one unit, and the whole thing runs on a schedule so your app always has the current numbers.
I built this for a rental site that shows prices in lei, euro and dollars, and pulled it out because every Moldovan app that touches money ends up needing the same thing.
Requirements
- PHP 8.3 or higher
- Laravel 12 or 13
Installation
composer require ihangan/laravel-moldova-exchange-rates
Publish and run the migration:
php artisan vendor:publish --tag="moldova-exchange-rates-migrations"
php artisan migrate
Then schedule the update (see Keeping the rates fresh) or run it once to get started:
php artisan bnm:update-rates
Usage
Everything goes through the Bnm facade.
use Ihangan\MoldovaExchangeRates\Facades\Bnm; Bnm::rates(); // ['MDL' => 1.0, 'EUR' => 20.105, 'USD' => 17.308, ...] Bnm::rate('EUR'); // 20.105 Bnm::date(); // '2026-06-04' — the day these rates are from // Convert between any two currencies it knows about. Bnm::convert(250, 'EUR', 'MDL'); // 5026.25 Bnm::convert(250, 'EUR', 'USD'); // 290.4 // Which way each currency moved against the previous publishing day. Bnm::trends(); // ['EUR' => 'up', 'USD' => 'down', ...]
All rates are stored as "MDL per one unit", so MDL is the pivot and is always present
with a rate of 1.0. convert() and the reads return null / empty when there are no
rates yet or a currency isn't tracked.
You can also reach the model directly:
use Ihangan\MoldovaExchangeRates\Models\ExchangeRate; ExchangeRate::query()->where('currency', 'EUR')->latest('effective_date')->first();
Keeping the rates fresh
The package ships the bnm:update-rates command. BNM updates rates on business days, so
twice a day is plenty. Add it to your scheduler:
use Illuminate\Support\Facades\Schedule; Schedule::command('bnm:update-rates')->twiceDaily(9, 15);
The fetch is a single light HTTP request, so the command runs inline. If you'd rather
push it onto a queue, dispatch the job instead with the --queue flag (your worker
runs it):
Schedule::command('bnm:update-rates --queue')->twiceDaily(9, 15);
Or skip the manual wiring and let the package schedule itself — set schedule in the
config to twice_daily, daily or hourly.
Configuration
php artisan vendor:publish --tag="moldova-exchange-rates-config"
return [ 'table' => 'bnm_exchange_rates', 'connection' => null, 'base' => 'MDL', 'currencies' => ['EUR', 'USD', 'RON', 'UAH'], 'endpoint' => env('BNM_RATES_ENDPOINT', 'https://www.bnm.md/en/official_exchange_rates'), 'http' => ['timeout' => 15, 'retries' => 2, 'lookback_days' => 4], 'cache' => ['key' => 'bnm-rates:snapshot', 'ttl' => 21600, 'store' => null], 'schedule' => false, // false | 'twice_daily' | 'daily' | 'hourly' ];
- currencies — which codes to fetch and store. Anything BNM publishes works (EUR, USD, RON, UAH, GBP, RUB, ...).
- lookback_days — BNM doesn't publish on weekends and holidays, so the client walks back up to this many days until it gets a valid response.
- cache — the latest snapshot is cached and refreshed automatically after each update.
- table — named
bnm_exchange_ratesso it won't clash with a table you already have.
How it reads BNM
The bank exposes an XML feed at bnm.md/en/official_exchange_rates?get_xml=1&date=dd.mm.yyyy.
Each currency carries a Nominal and a Value, so a rate quoted per 10 units (UAH, for
example) is normalised to one unit: rate = Value / Nominal. The effective date comes from
the feed itself, not from the request.
Testing
composer test
Tests fake the HTTP layer, so they never touch the BNM servers.
Changelog
See CHANGELOG.md and the releases.
Contributing
See CONTRIBUTING.md.
Security
Found a security issue? Email igorhangan@gmail.com instead of using the issue tracker. See SECURITY.md.
Credits
- Igor Hangan
- Exchange-rate data is published by the National Bank of Moldova.
License
The MIT License. See LICENSE.md.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-30
