PHPackages                             lahatre/laravel-money - 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. lahatre/laravel-money

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

lahatre/laravel-money
=====================

A precise, immutable, and float-safe money value object for Laravel.

v1.0.0(5mo ago)01PHPPHP ^8.0

Since Jan 12Pushed 5mo agoCompare

[ Source](https://github.com/lahatre/laravel-money)[ Packagist](https://packagist.org/packages/lahatre/laravel-money)[ RSS](/packages/lahatre-laravel-money/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

Lahatre Money
=============

[](#lahatre-money)

This package provides a precise and developer-friendly way to handle monetary values in Laravel.

It solves the common pitfalls of floating-point arithmetic (like `0.1 + 0.2 !== 0.3`) by using BCMath and integer storage under the hood. It offers a fluent API to perform calculations, handle rounding, and format prices, all while seamlessly integrating with Eloquent.

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

[](#installation)

You can install the package via composer:

```
composer require lahatre/money
```

Usage
-----

[](#usage)

### Preparing the database

[](#preparing-the-database)

We recommend storing money values as integers (minor units, e.g., cents).

```
Schema::create('products', function (Blueprint $table) {
    $table->id();
    // 10.00 is stored as 1000
    $table->bigInteger('price')->default(0);
    $table->timestamps();
});
```

### Preparing the model

[](#preparing-the-model)

Add the `MoneyCast` to your Eloquent model. This will automatically convert the integer from the database into a `Money` object instance.

```
use Illuminate\Database\Eloquent\Model;
use Lahatre\Money\Casts\MoneyCast;

class Product extends Model
{
    protected $casts = [
        'price' => MoneyCast::class,
    ];
}
```

### working with Money

[](#working-with-money)

You can assign values using strings, integers, or floats. The package will normalize them for you.

```
$product = new Product();

// You can assign a string (recommended for precision)
$product->price = '19.99';

// Or a float
$product->price = 19.99;

// The value is saved as an integer (1999)
$product->save();
```

When retrieving the value, you get an immutable `Money` instance.

```
// Automatic formatting as string
echo $product->price; // "19.99"

// Fluent arithmetic
$newPrice = $product->price->add('5.00'); // "24.99"
```

### Calculations &amp; Rounding

[](#calculations--rounding)

All operations return a new instance of `Money`. By default, the package uses Banker's Rounding (`HALF_UP`) and 2 decimals precision.

```
$price = Money::from('100.00');

// Chaining
$total = $price
    ->add('50.00')
    ->mul('0.20'); // Returns a new Money instance

// Splitting values (e.g. 10 / 3)
// You can define a specific rounding mode for operations that require it
use Lahatre\Money\Support\BigNumber;

$bill = Money::from('10.00');

$split = $bill->div(3, BigNumber::ROUND_UP); // "3.34"
```

### Configuration

[](#configuration)

You can publish the config file to change the default precision (e.g. for cryptocurrencies) or the global rounding mode.

```
php artisan vendor:publish --tag=money-config
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance70

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

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

173d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/139039151?v=4)[LAHAN Happiness](/maintainers/Tresor091005)[@Tresor091005](https://github.com/Tresor091005)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/lahatre-laravel-money/health.svg)

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

PHPackages © 2026

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