roaderchik / currency
用于处理 Laravel 5.8 的货币
1.0.5
2019-03-14 09:09 UTC
Requires
- php: >=5.4.0
- illuminate/cache: >=5.5
- illuminate/support: >=5.5
- illuminate/view: >=5.5
This package is auto-updated.
Last update: 2024-09-14 21:56:28 UTC
README
用于处理 Laravel 5.8 的货币。
安装
要获取 Currency 的最新版本,只需在您的 composer.json
文件中引用它。
"roaderchik/currency": "dev-master"
composer require "roaderchik/currency"
然后您需要运行 composer install
来下载它并更新自动加载器。
一旦 Currency 安装完成,您需要将服务提供者注册到应用程序中。打开 app/config/app.php
并找到 providers
键。
'providers' => [ roaderchik\Currency\CurrencyServiceProvider::class, ]
Currency 还包含一个外观,它提供了创建集合的静态语法。您可以在 app/config/app.php
文件的 aliases
键中注册外观。
'aliases' => [ 'Currency' => roaderchik\Currency\Facades\Currency::class, ]
使用 artisan 创建配置文件和迁移表
$ php artisan vendor:publish
Artisan 命令
更新汇率
默认情况下,汇率是从 Finance Yahoo.com 更新的。
php artisan currency:update
要从 OpenExchangeRates.org 更新
php artisan currency:update --openexchangerates
注意:使用 OpenExchangeRates.org 需要API密钥。将其添加到配置文件中。
To update from The Central Bank of the Russian Federation (www.cbr.ru)
php artisan currency:update --cbr
To update from National Bank of the Republic of Belarus (www.nbrb.by)
php artisan currency:update --nbrb
### Cleanup
Used to clean the Laravel cached exchanged rates and refresh it from the database. Note that cached exchanged rates are cleared after they are updated using one of the command above.
php artisan currency:cleanup
## Convert
~~~php
// for example convert USD to EUR
echo /Currency::convert(100, 'USD', 'EUR');
- 第一个参数是金额。
- 第二个参数是 ISO 4217 从货币代码。
- 第三个参数是 ISO 4217 到货币代码。
渲染
使用 Blade 辅助函数
@currency(12.00, 'USD')
- 第一个参数是金额。
- 可选 第二个参数是 ISO 4217 货币代码。如果没有设置,它将使用配置文件中设置的默认值。
echo /Currency::format(12.00, 'USD');
用于轻松输出舍入值
echo /Currency::rounded(12.80); // Will output $12 // All the parameters echo /Currency::rounded(12.80, 0, 'USD');