amkas/currency-converter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

amkas/currency-converter

最新稳定版本:v1.1.1

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

  1. Currency rates migration
  2. Currency Rate model
  3. 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

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-14