PHPackages                             lase-peco/unit-converter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lase-peco/unit-converter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lase-peco/unit-converter
========================

A simple unit converter.

1.2(4y ago)285MITPHPPHP ^7.4|^8.0

Since Sep 21Pushed 4y agoCompare

[ Source](https://github.com/lase-peco/unit-converter)[ Packagist](https://packagist.org/packages/lase-peco/unit-converter)[ RSS](/packages/lase-peco-unit-converter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Unit converter
==============

[](#unit-converter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/60dd2833ef2ba133e6f5fcc024cfd46fcc82dc753736ea86da806e396e1a09b9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6173652d7065636f2f756e69742d636f6e7665727465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lase-peco/unit-converter)[![Total Downloads](https://camo.githubusercontent.com/fb27c88d848062dad7261885993e48a92ff93b698f43ebdae28d225ff8b045b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6173652d7065636f2f756e69742d636f6e7665727465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lase-peco/unit-converter)

A simple unite converter library

Installation
------------

[](#installation)

Install the package via composer:

```
composer require lase-peco/unit-converter
```

Then publish the config file `conversions.php` with the following command

```
php artisan vendor:publish --provider="LasePeCo\UnitConverter\ServiceProvider"
```

The config file `conversions.php` contains all units of measurement and its values.

Define your own units
---------------------

[](#define-your-own-units)

First add your unit in the config file und the matching section, then it is recommended to create a class That extends the base package class.

Example: Say you want to add `KM^2` as an `Area` unit, first add the unit in the config file:

```
'area' => [
        'mm^2' => 1000000,
        'm^2' => 1, // base unit.
        'ft^2' => 10.7639,
        'yd^2' => 1.19598888894151,
        'km^2' => 0.000001, // your new unit and its value compared to the base unit.
    ],
```

Then create `Area` class in `App\Units\` which should extends the base `Area` class of this package:

```
