Open source
Money for Laravel
composer require roundly-consulting/money-for-laravelOverview
An immutable, arbitrary-precision Money and Currency toolkit for Laravel. Amounts live as exact minor units in canonical integer strings with bcmath arithmetic — no floats anywhere, no int64 ceiling — and every lossy operation rounds exactly once with PHP 8.4’s native RoundingMode. Around that core it ships ISO 4217 and custom currencies, locale formatting and parsing, Eloquent casts and schema macros, validation, discounts, tax and pluggable exchange rates (config, database, ECB). MIT-licensed and dependency-light: ext-bcmath, Laravel and two Roundly foundation packages — no third-party money library.
What you get
Exact minor units
Amounts are canonical integer strings with bcmath arithmetic — no float anywhere, up to 65 digits, so wei-precision crypto fits.
Currency safety
A bundled ISO 4217 list (165 currencies) plus custom currencies up to 18 decimals. Mixing currencies throws; conversion is always explicit.
One rounding, fair splits
Every lossy operation rounds exactly once with the native RoundingMode; allocate() and split() always sum back to the total.
Formatting & parsing
Formatting through ext-intl that stays digit-exact beyond 15 digits, a deterministic fallback, and a strict parser for localized input.
Eloquent, validation & HTTP
Casts, $table->money() schema macros, MoneyAmount and CurrencyCode rules, Request::money(), collection macros and @money.
Discounts & tax
Stackable discounts with caps, priorities and exclusivity; tax breakdowns where net + tax always equals gross.
Exchange rates
Config, database, ECB and chain drivers with exact cross rates and stale-rate guards — through the Exchange facade, an injected manager or actions, with a recording Exchange::fake().
Documentation
Installation
Install via Composer, publish the config, the exchange-rates migration and the validation messages only when you need them.
Configuration
Every config key and its default — currencies, schema precision, rounding, formatting, macros, exchange drivers, caching and the refresh schedule.
The Exchange & Currencies facades
Exchange converts, looks up rates, manages the stored rates table and fakes itself; Currencies reads and extends the currency registry.
DI and actions
Inject ExchangeManager or the CurrencyRegistry contract instead of the facades, or call the three rate actions directly with their DTOs.
The Money object
Create immutable Money values from minor, major or scaled amounts, read them exactly, and serialize them safely to JSON.
Arithmetic & comparison
Same-currency arithmetic that rounds exactly once, cash rounding, exact comparisons and sum, min, max and average aggregates.
Allocation & splitting
Split amounts by ratios or into equal parts without losing a cent, and spread an order discount across line totals exactly.
Multi-currency totals
Hold balances in several currencies with MoneyBag and total them into one currency with a single exact rounding.
Amounts & precision
The canonical integer grammar, hard limits, the int64 bridge and how money columns behave on PostgreSQL, MySQL and SQLite.
Rounding & math helpers
The eight native rounding modes, exact Ratio and Percentage values, MinorUnits helpers and RoundingModes for your own config.
Currencies
The bundled ISO 4217 registry, lookups by code or numeric code, custom currencies up to 18 decimals and input allow-lists.
Formatting & parsing
Locale-aware output with FormatOptions, a deterministic fallback formatter, a strict parser for localized input and the @money directive.
Eloquent casts & schema
Cast attributes to Money in one or two columns, create exact decimal money columns with schema macros, and query them correctly.
Validation, requests & collections
Validate amounts and currency codes, read money from requests without floats, aggregate collections and return a JSON resource.
Discounts
Percentage, fixed and free-shipping discounts with caps, priorities and exclusivity, three stacking strategies and an itemised breakdown.
Tax
Net, tax and gross from exact rates with one rounding per call, breakdowns where net + tax always equals gross, and invoice summaries.
Exchange rates
Explicit conversion through config, database, ECB or chain drivers, exact cross rates, manual rates, custom drivers and a production setup.
Commands, events & scheduling
Artisan commands for currencies and rates, the scheduled ECB refresh, queued refreshes, refreshing and pruning from code, and refresh events.
Exceptions
One MoneyException base class and a typed exception for every failure — mismatched currencies, rounding, overflow, rates and config.
Testing
Exchange::fake() swaps in static rates and records refreshes, stores and prunes — assert every call, seed the rates table, format byte-exact.
Migrating from a custom Money class
Map calls from a home-grown Money class onto this package — both can live side by side while call sites move over.
Requirements
PHP 8.4+ with ext-bcmath and Laravel 12 or 13; ext-intl and ext-simplexml are optional.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.