moneyphp/money
PHP library for handling money and currencies safely. Provides immutable Money and Currency value objects, arithmetic with proper rounding, comparisons, formatting, and allocation. Avoid floating-point errors in financial calculations; works well with PHP and frameworks like Laravel.
Architecture fit: Strong alignment with Laravel's domain-driven design principles. The immutable Money objects encapsulate business logic cleanly within the domain layer, avoiding leakage into controllers or infrastructure. Works seamlessly with Laravel's service container for currency configuration and formatters.
Integration feasibility: Composer-based installation requires minimal setup. Native support for ISO currency codes and formatters integrates with Laravel's localization system. Can be wrapped in custom value objects or used directly in service layers.
Technical risk: Requires refactoring existing float-based money handling; PHP 7.4+ requirement may affect legacy projects. Potential for subtle bugs if currency conversion rules are misapplied during arithmetic operations.
Key questions: How are current monetary values stored in the database (float vs integer)? What payment gateways or third-party integrations rely on raw float values? Are there legacy systems expecting monetary strings instead of minor-unit integers?
Stack fit: Ideal for Laravel’s service layer and domain models. Eloquent casts can handle Money objects for DB storage (storing minor units as integers). Middleware can parse input strings into Money objects during request handling.
Migration path: Start with new features using Money objects; incrementally refactor legacy code by creating adapters for existing float-based logic. Use database migrations to convert monetary columns to integer types storing minor units.
Compatibility: Requires PHP 7.4+ and Laravel 8+ for full compatibility. Payment gateway SDKs must support integer-based minor units (e.g., Stripe, PayPal). Verify third-party libraries don’t mutate Money objects.
Sequencing: 1) Install via Composer, 2) Configure currency rules in a service provider, 3) Update DB schema for minor-unit storage, 4) Implement Money in new features, 5) Gradually replace float-based calculations in existing code.
Maintenance: Low
How can I help you explore Laravel packages today?