quicktech-as / exchange-rate
使用ExchangeRate API将Laravel应用程序中的货币进行转换的包。
1.0.0
2017-05-05 00:35 UTC
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: ^6.2
- illuminate/support: ^5.2
Requires (Dev)
- phpunit/phpunit: ^6.1
- squizlabs/php_codesniffer: ^3.0
This package is not auto-updated.
Last update: 2024-09-29 02:29:51 UTC
README
Quicktech\ExchangeRate 是在 Laravel 5 应用程序中使用 ExchangeRate API 进行货币转换的一种简洁灵活的方式。
内容
安装
- 为了安装 Laravel 5,只需在您的 composer.json 中添加以下内容。然后运行
composer update
"quicktech-as/exchange-rate": "^1.0"
- 打开您的
config/app.php并将以下内容添加到providers数组中
Quicktech\ExchangeRate\ExchangeRateServiceProvider::class,
- 在相同的
config/app.php中,将以下内容添加到aliases数组中
'ExchangeRate' => Quicktech\ExchangeRate\Facade\ExchangeRate::class,
- 运行以下命令以发布包配置文件
config/exchange_rate.php
php artisan vendor:publish
配置
打开您的 .env 文件并设置您的 ExchangeRate 凭据
EXCHANGERATE_DEFAULT_CURRENCY = 'your default currency' EXCHANGERATE_API_KEY = 'your api key' EXCHANGERATE_API_URI = 'https://v3.exchangerate-api.com'
使用
根据默认货币获取汇率
要获取基于默认货币的所有汇率,您可以使用此资源
$rates = ExchangeRate::rates();
上述方法将返回以下响应
[
"AUD" => 1.32230,
"BGN" => 1.8096,
"BRL" => 3.11,
"..." => 1.31135,
"..." => 7.473, etc. etc.
]
转换货币值
要转换货币值,您可以使用此资源
$value = ExchangeRate::convert(10.00, 'USD', 'BRL'); // 31.11
许可证
Quicktech\ExchangeRate 是在 MIT 许可证条款下分发的免费软件。
贡献指南
请在问题页面报告您发现的所有问题。
欢迎提交拉取请求。