Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Money Laravel Package

brick/money

Brick\Money is a PHP library for precise, immutable money and currency values. It provides exact arithmetic (no float errors), explicit rounding control, and supports large amounts via brick/math, with optional GMP/BCMath acceleration.

View on GitHub
Deep Wiki
Context7

Money and currency library

Frequently asked questions about Money
How do I install brick/money in a Laravel project?
Run `composer require brick/money` in your project root. For PHP 8.1 or older, specify a compatible version like `0.10.*`. No Laravel-specific dependencies are required, making installation seamless. Ensure PHP 8.2+ is used for full feature support.
Can brick/money replace Laravel’s native float/decimal fields in models?
Yes. Use Eloquent’s `$casts` property to convert between database floats and `Money` objects. For example, `protected $casts = ['price' => Money::class];`. This ensures type safety and precision during serialization/deserialization.
What’s the difference between Money and RationalMoney in brick/money?
`Money` uses exact arithmetic for standard financial operations (e.g., USD 100.50), while `RationalMoney` handles complex calculations like fractional percentages or actuarial math without floating-point errors. Use `RationalMoney` only when precision demands it.
How does brick/money handle currency conversion with rounding?
Use `Money::of(100, 'USD')->to('EUR')` for conversions. Rounding is explicit via `CashContext` (e.g., for cash-based currencies like CHF) or `AutoContext` (dynamic scaling). Configure rounding rules per currency to match business logic.
Will brick/money work with Laravel’s service container for dependency injection?
Absolutely. Bind `MoneyService` or `CurrencyProvider` in a Laravel service provider to centralize money operations. Example: `$this->app->singleton(MoneyService::class, fn() => new MoneyService());`. This promotes reusability across controllers and services.
Are there performance concerns with brick/money in production?
Heavy calculations (e.g., `RationalMoney` chains) may impact latency. Enable GMP/BCMath extensions for faster operations. Benchmark critical paths like `Money::of('1000000', 'USD')->multipliedBy('1.1')` to ensure acceptable performance.
How do I test brick/money in Laravel unit tests?
Mock `IsoCurrencyProvider` for isolated tests. Use `Money::of('100', 'USD')` directly in assertions. For edge cases, test large amounts like `Money::of('999999999999.99', 'USD')` to validate precision. Laravel’s testing helpers work seamlessly with `Money` objects.
What’s the migration path from legacy float-based monetary logic?
Phase 1: Replace critical float fields (e.g., `Order::total`) with `Money` in new features. Phase 2: Add accessors/mutators to legacy models (e.g., `getTotalAttribute()`) to convert floats to `Money`. Use `MoneyBag` for multi-currency aggregations.
Does brick/money support deprecated or historical currencies (e.g., old franc codes)?
Yes, via `Currency::ofCountry('FR', '1999')` for historical contexts. Validate currency codes manually if relying on critical paths, as ISO 4217 updates may require adjustments. Cache `Currency` objects for repeated use.
What alternatives exist for precise financial calculations in Laravel?
Alternatives include `moneyphp/money` (simpler but less precise) or `bacon/bacon-qr-code` for non-monetary use cases. `brick/money` stands out for its immutable design, exact arithmetic, and Laravel-friendly integration (e.g., Eloquent casts, service providers).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai