PHPackages                             jobmetric/laravel-unit - 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. jobmetric/laravel-unit

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

jobmetric/laravel-unit
======================

This is a unit management package for Laravel that you can use in your projects.

2.1.0(1mo ago)6161MITPHPPHP &gt;=8.0.1

Since Aug 13Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/jobmetric/laravel-unit-converter)[ Packagist](https://packagist.org/packages/jobmetric/laravel-unit)[ Docs](https://doc.jobmetric.net/package/laravel-unit-converter)[ RSS](/packages/jobmetric-laravel-unit/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (7)Used By (0)

[![Contributors](https://camo.githubusercontent.com/46c78d7d1a6d63fed92302713a6f7b44c44ddb380727cbde4912528a5496bc27/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6a6f626d65747269632f6c61726176656c2d756e69742d636f6e7665727465722e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jobmetric/laravel-unit-converter/graphs/contributors)[![Forks](https://camo.githubusercontent.com/a089ae06bb71d050701f77b85df48e56fda34a7dad6f6eac2f13a76c92c2a453/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6a6f626d65747269632f6c61726176656c2d756e69742d636f6e7665727465722e7376673f7374796c653d666f722d7468652d6261646765266c6162656c3d466f726b)](https://github.com/jobmetric/laravel-unit-converter/network/members)[![Stargazers](https://camo.githubusercontent.com/774abda4e9b2b1e527333faedac48301276083a179887516ce8f1344268023f9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a6f626d65747269632f6c61726176656c2d756e69742d636f6e7665727465722e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jobmetric/laravel-unit-converter/stargazers)[![MIT License](https://camo.githubusercontent.com/27816db1445faa45f760f7079eb25692d5c31bafe246c0720bfc703c77aca8ee/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6f626d65747269632f6c61726176656c2d756e69742d636f6e7665727465722e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jobmetric/laravel-unit-converter/blob/master/LICENCE.md)[![LinkedIn](https://camo.githubusercontent.com/eb590f47a3fca74584d18db8dd3e985ae3d786f50cd41b7530c3af3885da233c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2d4c696e6b6564496e2d626c75652e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d6c696e6b6564696e26636f6c6f72423d353535)](https://linkedin.com/in/majidmohammadian)

Laravel Unit Converter
======================

[](#laravel-unit-converter)

**Unit Management for Laravel. Flexible. Precise.**

Laravel Unit Converter helps you manage and convert measurement units in a clean, consistent way—from Weight and Length to Currency, Volume, Temperature, and 30+ other unit types. It is designed to be used as a reusable package in real-world Laravel applications where unit conversion needs to be normalized and shared across multiple models.

Why Laravel Unit Converter?
---------------------------

[](#why-laravel-unit-converter)

### Comprehensive Unit Type Support

[](#comprehensive-unit-type-support)

Support for 30+ unit types out of the box:

- **Physical Units**: Weight, Length, Volume, Area, Temperature, Pressure, Speed, Force, Energy, Power, and more
- **Digital Units**: Data Storage, Data Transfer
- **Scientific Units**: Electric Current, Voltage, Resistance, Capacitance, Inductance, Magnetic Flux, Radiation
- **Everyday Units**: Currency, Time, Cooking measurements, Fuel Consumption

### Flexible Base Unit System

[](#flexible-base-unit-system)

Each unit type has a base unit (value = 1) that serves as the conversion reference. All other units in the same type are defined relative to this base, making conversions accurate and consistent.

### Service-first API + Facade

[](#service-first-api--facade)

The `UnitConverter` service provides a complete API for:

- Creating and managing units
- Converting values between units
- Changing base units dynamically
- Tracking unit usage across your application

Quick Start
-----------

[](#quick-start)

Install via Composer:

```
composer require jobmetric/laravel-unit-converter
```

Run migrations:

```
php artisan migrate
```

Optionally publish config/translations (if you need to override defaults):

```
php artisan vendor:publish --provider="JobMetric\\UnitConverter\\UnitConverterServiceProvider"
```

Usage (Examples)
----------------

[](#usage-examples)

Store a unit using the Facade:

```
use JobMetric\UnitConverter\Facades\UnitConverter;

$response = UnitConverter::store([
    'type' => 'weight',
    'value' => 1000,       // 1 kilogram = 1000 grams (if gram is base)
    'status' => true,
    'translation' => [
        'en' => [
            'name' => 'Kilogram',
            'code' => 'kg',
        ],
        'fa' => [
            'name' => 'کیلوگرم',
            'code' => 'کیلوگرم',
        ],
    ],
]);
```

Convert between units:

```
use JobMetric\UnitConverter\Facades\UnitConverter;

// Convert 5 kilograms to grams
$result = UnitConverter::convert($kilogramUnitId, $gramUnitId, 5);
// Result: 5000

// Or use the helper function
$result = unitConvert($kilogramUnitId, $gramUnitId, 5);
```

Attach units to your models using traits:

```
use Illuminate\Database\Eloquent\Model;
use JobMetric\UnitConverter\HasUnit;

class Product extends Model
{
    use HasUnit;

    protected array $unitables = [
        'weight' => 'weight',
        'length' => 'length',
        'width'  => 'length',
        'height' => 'length',
    ];
}
```

Assign units to a model:

```
$product->fill([
    'unit' => [
        'weight' => ['unit_id' => 1, 'value' => 2.5],
        'length' => ['unit_id' => 2, 'value' => 30],
        'width'  => ['unit_id' => 2, 'value' => 20],
        'height' => ['unit_id' => 2, 'value' => 10],
    ]
]);
$product->save();
```

Available Artisan Commands
--------------------------

[](#available-artisan-commands)

```
# List all registered units
php artisan unit:list

# Convert a value between units
php artisan unit:convert

# Export units to file
php artisan unit:export

# Seed default units
php artisan unit:seed
```

Documentation
-------------

[](#documentation)

Documentation for Laravel Unit Converter is available here:

**[📚 Read Full Documentation →](https://jobmetric.github.io/packages/laravel-unit-converter/)**

The documentation includes:

- **Getting Started** - Installation and configuration
- **Traits** - `HasUnit` for attaching units to models
- **Services &amp; Facades** - Complete API reference for UnitConverter
- **Unit Types** - All 30+ supported unit types
- **Requests &amp; Resources** - Validation and API responses
- **Events** - Hook into lifecycle events (`UnitStoreEvent`, `UnitUpdateEvent`, `UnitDeleteEvent`)
- **Helper Functions** - `unitConvert()` and more
- **Testing** - How to run package tests and expected patterns

Contributing
------------

[](#contributing)

Thank you for participating in `laravel-unit-converter`. A contribution guide can be found [here](CONTRIBUTING.md).

License
-------

[](#license)

The `laravel-unit-converter` is open-sourced software licensed under the MIT license. See [License File](LICENCE.md) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance89

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~116 days

Recently: every ~146 days

Total

6

Last Release

54d ago

Major Versions

1.3.0 → 2.0.02026-02-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/b00d08bd4b0b765ee2d33719a535e6cb49c04fb945078a0809d5c05e6f16ee96?d=identicon)[majidmohammadian](/maintainers/majidmohammadian)

---

Top Contributors

[![MajidMohammadian](https://avatars.githubusercontent.com/u/2099965?v=4)](https://github.com/MajidMohammadian "MajidMohammadian (130 commits)")[![hassan7303](https://avatars.githubusercontent.com/u/128932029?v=4)](https://github.com/hassan7303 "hassan7303 (1 commits)")

---

Tags

unitlaravelpackageconversionconvertermanagementmeasurementjobmetric

### Embed Badge

![Health badge](/badges/jobmetric-laravel-unit/health.svg)

```
[![Health](https://phpackages.com/badges/jobmetric-laravel-unit/health.svg)](https://phpackages.com/packages/jobmetric-laravel-unit)
```

###  Alternatives

[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
