amkas/currency-converter
Composer 安装命令:
composer require amkas/currency-converter
包简介
Currency Converter is a simple easy to use package for Laravel for currency conversion.
README 文档
README
Currency Converter is a simple easy to use package for Laravel for currency conversion.
Getting Started
Install Currency Converter via composer. Note: If you do not have composer yet, you can install it by following the instructions on https://getcomposer.org
Step 1. Install package
composer require amkas/currency-converter
Step 2. Register the Currency Converter service provider (Optional)
in bootstrap/providers.php you can add following line
\Amkas\CurrencyConverter\ConversionServiceProvider::class,
Step 3. Publish Assets
To publish the assets run the below command.
php artisan vendor:publish --tag=amkas-currency-converter
Or
php artisan vendor:publish --provider="Amkas\CurrencyConverter\ConversionServiceProvider"
This command will copy three files as below:
Copying file [amkas\currency-converter\src\Models\CurrencyRate.php] to [app\Models\CurrencyRate.php] DONE Copying file [amkas\currency-converter\src\config\currency_converter.php] to [config\currency_converter.php] DONE Copying directory [amkas\currency-converter\src\database\migrations] to [database\migrations] DONE
So there are three files
- Currency rates migration
- Currency Rate model
- config/currency-converter.php
After that, you need to run the migration command to migrate the currency rates table into database as below:
php artisan migrate
Then you can set the default currency in config file as below:
'default_currency' => 'USD',
and other config settings.
After that, you can create a CRUD to save the currency rates into database
Usage:
In Controller include Currency Facade and call as below:
use Amkas\CurrencyConverter\Facades\Currency; $convertedAmount = Currency::convertAmount(10, 'EUR');
If you want to use a helper's function use below.
$convertedAmount = convertAmount(10, 'EUR');
If you want to convert amount from one currency to another using Currency Facade, call chain functions as below:
$convertedAmount = Currency::amount(10) ->from('EUR') ->to("USD") ->convert();
with helper functions you can call as below:
$convertedAmount = amount(10) ->from("EUR") ->to("USD") ->convert();
Note: Since this currency converter has cache implemented to avoid database query everytime when currency conversion function will call, so every time when new currency rate will add via CurrencyRate model, the cahce will automatically reset.
However, you can reset that specific cache by runing the below command:
php artisan converter:reset-cache
amkas/currency-converter 适用场景与选型建议
amkas/currency-converter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 09 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「currency」 「laravel」 「currency converter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 amkas/currency-converter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 amkas/currency-converter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 amkas/currency-converter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
Encode integer IDs using a preset or customized symbol set
Fixer.io data provider for Peso
TCMB Currenct Converter
Immutable PHP currency converter that's data-agnostic.
Alfabank REST API integration
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-14