PHPackages                             sfolador/measures-for-laravel - 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. sfolador/measures-for-laravel

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

sfolador/measures-for-laravel
=============================

A collection of unit conversions utils for Laravel

0.1.9(1y ago)104.5k↓39.3%4[2 PRs](https://github.com/sfolador/measures-for-laravel/pulls)MITPHPPHP ^8.1|^8.2|^8.3CI passing

Since Feb 18Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/sfolador/measures-for-laravel)[ Packagist](https://packagist.org/packages/sfolador/measures-for-laravel)[ Docs](https://github.com/sfolador/measures-for-laravel)[ RSS](/packages/sfolador-measures-for-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (14)Used By (0)

[![](https://camo.githubusercontent.com/ac2ba8bf1ad0f1d6abc1ddbcffb79461cda5ba705f30e9ae7bc451f444bb2a31/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4d65617375726573253230666f722532304c61726176656c2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d73666f6c61646f722532466d656173757265732d666f722d6c61726176656c267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d456173696c792b636f6e766572742b6265747765656e2b756e6974732b6f662b6d656173757265266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d63616c63756c61746f72267769647468733d32303026686569676874733d6175746f)](https://camo.githubusercontent.com/ac2ba8bf1ad0f1d6abc1ddbcffb79461cda5ba705f30e9ae7bc451f444bb2a31/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4d65617375726573253230666f722532304c61726176656c2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d73666f6c61646f722532466d656173757265732d666f722d6c61726176656c267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d456173696c792b636f6e766572742b6265747765656e2b756e6974732b6f662b6d656173757265266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d63616c63756c61746f72267769647468733d32303026686569676874733d6175746f)

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

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/99063e32d5a7d2c7d72358591545109cda952b1864ea71f744895475fe583975/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73666f6c61646f722f6d656173757265732d666f722d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sfolador/measures-for-laravel)[![GitHub Tests Action Status](https://camo.githubusercontent.com/a90f564a151cb7b4c3d13bc6aeadefa7ab3aa576385e4a94c1bf147afd1bfe0d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73666f6c61646f722f6d656173757265732d666f722d6c61726176656c2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/sfolador/measures-for-laravel/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d0c8c0e4b902bc0438380db2a225fa73e8dfc0fec67eba1a20be794bcb131aa5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73666f6c61646f722f6d656173757265732d666f722d6c61726176656c2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/sfolador/measures-for-laravel/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/3d3419bc6861543a998dfe9ef8ceb3179f7fbbaf448f1d6ce6dfde9c61396e48/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73666f6c61646f722f6d656173757265732d666f722d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sfolador/measures-for-laravel)

Convert units of measure in Laravel.

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

[](#installation)

You can install the package via composer:

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

You can publish the config file with:

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

Usage
-----

[](#usage)

```
use \Sfolador\Measures\Measures;
use  \Sfolador\Measures\Unit\Length\Length;
\Sfolador\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 \Sfolador\Measures\Unit\Weight\Weight;
use Sfolador\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)

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

License
-------

[](#license)

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

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance59

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 74.5% 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 ~71 days

Recently: every ~160 days

Total

10

Last Release

541d ago

PHP version history (2 changes)0.1.0PHP ^8.1

0.1.8PHP ^8.1|^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/54c6b8884e3bd4e86d26de024ca07094728adc7db2a8a483538222121b00f9f1?d=identicon)[sfolador](/maintainers/sfolador)

---

Top Contributors

[![sfolador](https://avatars.githubusercontent.com/u/36632?v=4)](https://github.com/sfolador "sfolador (108 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (22 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (15 commits)")

---

Tags

laravelmeasurephpunits-of-measurelaravelsfoladormeasures-for-laravel

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/sfolador-measures-for-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/sfolador-measures-for-laravel/health.svg)](https://phpackages.com/packages/sfolador-measures-for-laravel)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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