mgcodeur / laravel-currency-converter
Laravel货币转换器:轻松在Laravel应用程序中转换货币,无需API密钥。它快速、简单且完全免费。
1.0.5
2024-04-29 09:06 UTC
Requires
- php: ^8.1||^8.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.10.0||^8.1.1
- orchestra/testbench: ^8.22.0||^9.0.0
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-08-31 09:21:53 UTC
README
Laravel货币转换器:轻松在Laravel应用程序中转换货币,无需API密钥。它快速、简单且完全免费。
📦 安装
您可以通过composer安装此包
composer require mgcodeur/laravel-currency-converter
Composer安装了Laravel货币转换器包后,您可以运行currency-converter:install
Artisan命令
php artisan currency-converter:install
✍🏻 基本用法
转换一种货币到另一种货币
// convert 10 USD to MGA $convertedAmount = CurrencyConverter::convert(10) ->from('USD') ->to('MGA') ->get(); dd($convertedAmount);
注意:不要忘记导入CurrencyConverter Facades
use Mgcodeur\CurrencyConverter\Facades\CurrencyConverter;
转换所有货币
当您没有指定to
方法时,您可以转换所有货币。
// convert 5 EUR to all currencies $convertedAmount = CurrencyConverter::convert(5) ->from('EUR') ->get(); dd($convertedAmount);
获取所有货币
要获取所有货币,您可以使用currencies
方法。
$currencies = CurrencyConverter::currencies()->get(); dd($currencies);
格式化输出结果
您可以使用format
方法来格式化输出结果,而不是使用get
方法。
// convert 10 USD to EUR and format the result $convertedAmount = CurrencyConverter::convert(10) ->from('USD') ->to('EUR') // you don't need to specify the to method if you want to convert all currencies ->format(); dd($convertedAmount);
默认情况下,千位分隔符是逗号(,),小数分隔符是点(.)。您可以在发布的配置文件中更改这些分隔符(config/currency-converter.php
)。
如果您打开配置文件,您将看到以下代码
return [ 'currency' => [ 'format' => [ 'decimals' => 2, // change this to 0 if you want result like 1.000, or 3 if you want result like 1.000.000 'decimal_separator' => ',', // change this to '.' if you want result like 1.000,00, or space if you want result like 1 000,00 'thousand_separator' => '.', // change this to ',' if you want result like 1,000.00, or '.' if you want result like 1 000.00 ] ], ];