juanparati/laravel-exchanger 问题修复 & 功能扩展

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

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

juanparati/laravel-exchanger

最新稳定版本:12.0

Composer 安装命令:

composer require juanparati/laravel-exchanger

包简介

A currency exchange rate library for Laravel

README 文档

README

Laravel-Exchanger

A Laravel currency converter library that uses florianv/exchanger.

Installation

composer require juanparati/laravel-exchanger

Facade registration (optional):

'aliases' => [
    ...
    'CurrencyExchanger' => \Juanparati\LaravelExchanger\Facades\ExchangerConverterFacade,
    ...
]

Configuration

Publish configuration file:

artisan vendor:publish --provider="Juanparati\LaravelExchanger\Providers\ExchangerServiceProvider"

The configuration contains a list of services, check the florianv/exchanger documentation in order to know the description and characteristics of each service.

It's important to provide a valid cache time (in seconds) in order to avoid duplicate requests.

Usage

Get the currency rate

$rate = CurrencyExchanger::getRate('eur', 'pln'); // Return Exchanger\ExchangeRate
$rate->getValue();                                // Returns rate as float
$rate->getDate()->format('Y-m-d')                 // Returns exchange date

// Historical rate
CurrencyExchanger::getRate('nok', 'sek', now()->subDays(10));

Convert currency

CurrencyExchanger::convert('ron', 'dkk', 10); // Convert 10 RON to DKK and return as float

// Historical conversion rate 
CurrencyExchanger::convert('ron', 'dkk', 10, now()->subDays(5));

// Obtain the last rate (Exchanger\ExchangeRate) for the previous currency conversion
CurrencyExchanger::getLastExchangeRateResult();

Cache state

Is sometimes convenient to disable the cache in order of force to request the most recent rate or conversion. In order to achieve that is possible to disable temporally the cache:

CurrencyExchanger::setCacheStatus(false); // Cache disabled
CurrencyExchanger::setCacheStatus(true);  // Cache enabled

Remember that cache is always enabled by default when the configuration key "cache_time" has a valid integer.

Attach/Detach services on-demand

It's possible to attach and detach services on demand:

// Detach service
CurrencyExchanger::detach(\Exchanger\Service\Cryptonator::class);

// Attach service
CurrencyExchanger::attach(\Exchanger\Service\Cryptonator::class);

By default all the services registered into the configuration are attached by default.

Execute custom queries

Because this library works as a wrapper for florianv/exchanger it's possible to execute custom queries passing the build query to the "executeQuery" method.

...
CurrencyExchanger::executeQuery($query->build);
...

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固