PHPackages                             grnspc/measure - 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. grnspc/measure

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

grnspc/measure
==============

A collection of unit conversions utils for Laravel

v0.1(1y ago)01MITPHPPHP ^8.3

Since May 10Pushed 1y agoCompare

[ Source](https://github.com/grnspc/measure)[ Packagist](https://packagist.org/packages/grnspc/measure)[ Docs](https://github.com/grnspc/measure)[ GitHub Sponsors](https://github.com/sponsors/grnspc)[ RSS](/packages/grnspc-measure/feed)WikiDiscussions main Synced 1mo ago

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

[![](https://camo.githubusercontent.com/611156cbd816f8eb90731108c1eafa0b8912bd265b0d11b4579b606501f13955/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4d65617375726573253230666f722532304c61726176656c2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d47726e7370632532466d656173757265732d666f722d6c61726176656c267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d456173696c792b636f6e766572742b6265747765656e2b756e6974732b6f662b6d656173757265266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d63616c63756c61746f72267769647468733d32303026686569676874733d6175746f)](https://camo.githubusercontent.com/611156cbd816f8eb90731108c1eafa0b8912bd265b0d11b4579b606501f13955/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4d65617375726573253230666f722532304c61726176656c2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d47726e7370632532466d656173757265732d666f722d6c61726176656c267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d456173696c792b636f6e766572742b6265747765656e2b756e6974732b6f662b6d656173757265266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d63616c63756c61746f72267769647468733d32303026686569676874733d6175746f)

A collection of unit conversions utils for Laravel
==================================================

[](#a-collection-of-unit-conversions-utils-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/61017c5d54b249aad59bafbf0e97b9a8133929bee69484a67a1095a8e4a1f287/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f47726e7370632f6d656173757265732d666f722d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Grnspc/measures-for-laravel)[![GitHub Tests Action Status](https://camo.githubusercontent.com/53de954de8f6163aa3a5d25c8d26945a2b6a38f9b3301ba8f79e3f02a39665b6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f47726e7370632f6d656173757265732d666f722d6c61726176656c2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/Grnspc/measures-for-laravel/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/f40f7b040d63883e44afb158a6c54a718d25c6f5dbdcbd6d49ff7558ed7b9263/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f47726e7370632f6d656173757265732d666f722d6c61726176656c2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/Grnspc/measures-for-laravel/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/9f64e459b96226c998b70aeb60bb3ff1ce5462eafb9c41dd94ab8cc6cd8119c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f47726e7370632f6d656173757265732d666f722d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Grnspc/measures-for-laravel)

Convert units of measure in Laravel.

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

[](#installation)

You can install the package via composer:

```
composer require Grnspc/measures-for-laravel
```

You can publish the config file with:

```
php artisan vendor:publish --tag="measures-for-laravel-config"
```

Usage
-----

[](#usage)

```
use \Grnspc\Measures\Measures;
use  \Grnspc\Measures\Unit\Length\Length;
\Grnspc\Measures\Unit\Weight\Weight;

$measure = Measures::length("2.0m");
echo $measures->toCm(); // 200.0 cm

//or you can use the Length class directly

$length = Length::from("2.0m");
echo $length->toCm(); // 200.0 cm

$measure = Measures::weight("2.0Kg");
echo $measures->toG(); // 2000.0 g

//or you can use the Weight class directly

$length = Weight::from("2.0Kg");
echo $length->toG(); // 2000.0 g
```

It's possible to use also extended fluent methods:

```
$measure = Length::from("2.0m");
echo $measures->toCentimeters(); // 200 cm

//you can chain the methods:

echo  Length::from("2.0m")->toCentimeters(); // 200 cm
```

If you do not know which kind of measure you are dealing with, you can use the `Measures` class to automatically detect the type of measure:

```
$measure = Measures::from("2.0m"); // $measure is an instance of Length
echo $measures->toCm(); // 200 cm

$measure = Measures::from("2.0Kg"); // $measure is an instance of Weight
echo $measures->toG(); // 2000 g
```

Eloquent cast
-------------

[](#eloquent-cast)

It's possible to cast a model attribute to a measure:

```
use \Grnspc\Measures\Unit\Weight\Weight;
use Grnspc\Measures\Cast\Measure;

class Product extends Model
{
    protected $casts = [
        'weight' => Measure::class,
        'length'   => Measure::class,
    ];
}

$product = Product::first();
echo $product->weight->toKg(); // 2 Kg
echo $product->length->toCm(); // 200 cm

$product->weight = Weight::from("3.0Kg");
$product->length = Length::from("1.0m");

$product->save();
echo $product->weight->toKg(); // 3 Kg
echo $product->length->toCm(); // 100 cm
```

Available units
---------------

[](#available-units)

### Length

[](#length)

- Millimeter
- Centimeter
- Meter
- Kilometer
- Inch
- Foot
- Yard
- Mile
- Nautical mile

### Weight

[](#weight)

- Milligram
- Gram
- Kilogram
- Ton
- Ounce
- Pound
- Stone
- Long ton
- Short ton

### Volume

[](#volume)

- Milliliter
- Liter
- Cubic meter
- Cubic inch
- Cubic foot
- Gallon
- Pint
- Cup

### Temperature

[](#temperature)

- Celsius
- Fahrenheit
- Kelvin

### Area

[](#area)

- Square meter
- Square kilometer
- Square centimeter
- Square millimeter
- Square inch
- Square foot
- Square yard
- Square mile
- Acre
- Hectare

### Data

[](#data)

- Bit
- Byte
- Kilobit
- Kilobyte
- Megabit
- Megabyte
- Gigabit
- Gigabyte
- Terabit
- Terabyte
- Petabit
- Petabyte
- kibibit
- kibibyte
- mebibit
- mebibyte
- gibibit
- gibibyte
- tebibit
- tebibyte
- pebibit
- pebibyte

### Speed

[](#speed)

- Meter per second
- Kilometer per hour
- Mile per hour
- Knot
- Foot per second
- Mach

### Time

[](#time)

- Nanosecond
- Microsecond
- Millisecond
- Second
- Minute
- Hour
- Day
- Week
- Month
- Year

### Pressure

[](#pressure)

- Pascal
- Kilopascal
- Bar
- Millibar
- Atmosphere
- Torr
- Pound per square inch
- Millimeter of mercury

### Energy

[](#energy)

- Joule
- Kilojoule
- Megajoule
- Gigajoule
- Watt hour
- Kilowatt hour
- Megawatt hour
- Gigawatt hour
- Calorie
- Kilocalorie
- Megacalorie
- Gigacalorie
- Electronvolt
- Kiloelectronvolt
- Megaelectronvolt
- Gigaelectronvolt

### Angle

[](#angle)

- Degree
- Radian

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Grnspc](https://github.com/Grnspc)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance49

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

373d ago

### Community

Maintainers

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

---

Top Contributors

[![greenspace10](https://avatars.githubusercontent.com/u/55725358?v=4)](https://github.com/greenspace10 "greenspace10 (3 commits)")

---

Tags

laravelmeasures-for-laravel

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/grnspc-measure/health.svg)

```
[![Health](https://phpackages.com/badges/grnspc-measure/health.svg)](https://phpackages.com/packages/grnspc-measure)
```

###  Alternatives

[highideas/laravel-users-online

This package will provide an online users management.

203113.2k1](/packages/highideas-laravel-users-online)[stephenjude/filament-blog

Filament Blog Builder

20317.8k](/packages/stephenjude-filament-blog)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[datomatic/nova-detached-actions

A Laravel Nova tool to allow for placing actions in the Nova toolbar detached from the checkbox selection mechanism.

11229.2k](/packages/datomatic-nova-detached-actions)[sfolador/measures-for-laravel

A collection of unit conversions utils for Laravel

104.5k](/packages/sfolador-measures-for-laravel)

PHPackages © 2026

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