extradevs / laravel-mnb
Laravel MNB (Magyar Nemzeti Bank)
v2.1.0
2024-06-06 12:57 UTC
Requires
- php: ^8.1
- extradevs/mnb: 2.0.0
- illuminate/cache: ^10
- illuminate/support: ^10
Requires (Dev)
- mockery/mockery: 1.6.12
- orchestra/testbench: ^8.42.2
- phpunit/phpunit: ^9.5
This package is not auto-updated.
Last update: 2024-09-27 09:35:37 UTC
README
要求
此包需要 Soap 以及 PHP 7.1 版本或更高。
专业知识
此包基于此 MNB 包 构建。请查看相应的文档。
安装
composer require extradevs/laravel-mnb
配置
导出
php artisan vendor:publish --provider="SzuniSoft\Mnb\Laravel\MnbServiceProvider" --tag="config"
config/mnb-exchange.php
/*
* Wsdl file location.
* */
'wsdl' => env('MNB_SOAP_WSDL', 'http://www.mnb.hu/arfolyamok.asmx?wsdl'),
'cache' => [
/*
* Desired cache driver for service.
* */
'store' => env('MNB_CACHE_DRIVER', 'file'),
/*
* Minutes the cached currencies will be held for.
* Default: 24hrs (1440)
* */
'minutes' => env('MNB_CACHE_MINUTES', 1440),
]
使用方法
通过外观访问
use Extradevs\Mnb\Laravel\Facade\Mnb
$currency = Mnb::currentExchangeRate('EUR');
由应用程序容器解析
$currency = app(\Extradevs\Mnb\Laravel\Client::class)->currentExchangeRate('EUR');
通过引用访问刷新日期
您可以通过传递 $date 变量到某些方法来检查数据源日期。这些方法将变量转换为 Carbon 实例。
Mnb::exchangeRates($date);
$date->isToday();
可用方法
不使用缓存
这些方法不会使用和更新缓存。
- currentExchangeRate($code, &$date = null): Currency
- currentExchangeRates(&$date = null): Currency 数组
使用缓存
这些方法将使用缓存。
- exchangeRate($code, &$date = null): 单一 Currency
- exchangeRates(&$date = null): Currency 数组
- currencies(): 字符串数组(每个是货币代码)
- hasCurrency($code): 布尔值