Looking to hire Laravel developers? Try LaraJobs
This package is not available.

money-for-laravel maintained by roundly-consulting

Description
Immutable arbitrary-precision Money and Currency value objects for Laravel: ISO 4217 + custom currencies, exact decimal parsing, rounding-safe arithmetic and allocation, locale formatting, Eloquent casts and schema macros, validation, discounts, tax, and pluggable exchange rates (array, database, ECB).
Last update
2026/10/03 19:55 (dev-main)
License
Downloads
51

Comments
comments powered by Disqus

Money for Laravel

Immutable, arbitrary-precision Money and Currency value objects for Laravel: exact decimal parsing, rounding-safe arithmetic and allocation, locale formatting, Eloquent casts, validation, discounts, tax and pluggable exchange rates. Amounts are minor units held as integer strings with bcmath arithmetic, so there is no float anywhere and no int64 ceiling.

Installation

Requires PHP 8.4 (ext-bcmath; ext-intl for locale-aware formatting) and Laravel 12 or 13.

composer require roundly-consulting/money-for-laravel

Usage

Calculate with exact amounts. Every lossy step rounds once, and currencies never mix silently:

use RoundlyConsulting\Money\Money;

$price = Money::ofMajor('19.99', 'EUR');                          // minor "1999", never a float
$total = $price->add(Money::ofMinor(250, 'EUR'))->multiply(3);    // 67.47 EUR, exact
[$a, $b, $c] = $total->allocate(1, 1, 1);                         // parts always sum back to $total
$total->add(Money::ofMajor('1', 'USD'));                          // throws CurrencyMismatch

$total->toDecimal();       // "67.47"
$total->format('sk');      // "67,47 €"

Store it on a model: $table->money('price') creates the amount and currency columns:

use RoundlyConsulting\Money\Casts\AsMoney;

Schema::create('products', function (Blueprint $table) {
    $table->id();
    $table->money('price');                       // decimal(38,0) price + price_currency
    $table->timestamps();
});

final class Product extends Model
{
    protected function casts(): array
    {
        return ['price' => AsMoney::class];
    }
}

$product = Product::create(['price' => Money::ofMajor('19.99', 'EUR')]);

Convert with the Exchange facade (ECB rates by default, no setup):

use RoundlyConsulting\Money\Facades\Exchange;

$product->price->convertTo('USD');                    // Money in USD at today's rate
Exchange::convertWithRate($product->price, 'CZK');    // Conversion: original, converted, rate

Documentation

The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/money-for-laravel

Release notes are in CHANGELOG.md. To contribute, see the contributing guide.

Support our work

This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.

License

The MIT License (MIT). See LICENSE.md.