devsquared/unitconvert-laravel 问题修复 & 功能扩展

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

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

devsquared/unitconvert-laravel

Composer 安装命令:

composer require devsquared/unitconvert-laravel

包简介

UnitConvert API Wrapper for Laravel

README 文档

README

Latest Version GitHub license

With the UnitConvert.io wrapper for Laravel, you can quickly and easily compare and convert units of measurement programmatically.

This package was created and developer by DevSquared - a consultant and development agency located in Pittsburg, KS, USA. Check out our website to learn more information about us.

Installation

UnitConvert requires an API key to use this wrapper. You can sign up for a free account today and get started. This package can be installed through Composer.

composer require devsquared/unitconvert-laravel

In Laravel 5.5 and above, the package will autoregister the provider and the alias. For Laravel 5.4 and below, you must install the provider and the alias.

// config/app.php
'providers' => [
    ...
    DevSquared\UnitConvert\UnitConvertProvider::class,
    ...
];

'aliases' => [
    ...
    'UnitConvert' => DevSquared\UnitConvert\UnitConvertFacade::class,
    ...
];

Next, you will need to add your API key to the config. You can add it to your .env file as

UNITCONVERT_API_KEY=

Optionally, you can publish the config file of this package with this command:

php artisan vendor:publish --provider="DevSquared\UnitConvert\UnitConvertServiceProvider"

Usage

The UnitConvert database contains variants as people use the system. Commonly misspellings, abbreviations, and full words are all excepted strings in addition to the measurement value. Below is an example of how to compare and convert a unit of measurement(s).

use UnitConvert;

// Get Information for a Unit of Measurement
$response = UnitConvert::getMeasurementInfo('20 miles');
$response->getSuccess(); // Returns true
$response->getError(); // Returns the response error message, if success is false
$response->getAmount(); // Returns 20
$response->getUnit(); // Returns "Miles"
$response->getDisplay(); // Returns "20 Miles"
$response->getCategory(); // Returns "Length"
$response->getVariants(); // Returns ["Mile","Miles","mi"]
$response->getConvertableTo(); // Returns ["Centimeters","Millimeters","Meters","Inches","Feet","Yards","Miles","Decimeters","Kilometers","Astronomical Units","Light Years","Parsecs","Nautical Miles"]

// Comparing a Measurement
$response = UnitConvert::compare('10mg', '==', '10 pounds');
$response->getSuccess(); // Returns true
$response->getError(); // Returns the response error message, if success is false
$response->getResult(); // Returns false

// Converting a Measurement
$response = UnitConvert::convert('20 miles', 'kilometers');
$response->getSuccess(); // Returns true
$response->getError(); // Returns the response error message, if success is false
$response->getAmount(); // Returns 32.1868
$response->getUnit(); // Returns "Kilometers"
$response->getDisplay(); // Returns "32.18680 Kilometers"

Here is an example use case for the convert function:

$response = UnitConvert::convert('20 miles', 'gallons');
if ($response->getSuccess() == false) {
    return $response->getError();
}

return $response->getDisplay();

Changelog

Please see the changelog for more information on what has changed recently.

Using this? Let us know!

We really enjoy seeing our work being used in production environments. If you decide to implement this wrapper, feel free to let us know and share your work. You can send us an email on our website: https://dev-squared.com

License

The MIT License (MIT). Please see the License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固