- How do I install roundly-consulting/money-for-laravel in a Laravel app?
- Install it with Composer by running composer require roundly-consulting/money-for-laravel. Laravel package auto-discovery registers the service provider and facade, so no manual provider entry is usually needed. If the package ships a config file, publish it with php artisan vendor:publish and review currency defaults.
- Which Laravel and PHP versions does money-for-laravel support?
- The package is a standard Composer Laravel package and integrates through a service provider and facade. Check the require section of its composer.json for the exact Laravel and PHP constraints before adding it to an existing project. Because it is at a 1.0.x release line, confirm compatibility in CI before upgrading across major Laravel versions.
- How does money-for-laravel prevent floating-point errors?
- It represents amounts as integer minor units, such as cents, inside immutable Money objects. Arithmetic happens on integers with precision and overflow protection instead of binary floats. That keeps prices, totals, and invoice calculations exact and testable.
- How do I store Money values in the database with Eloquent casts?
- Use the package's Eloquent cast to persist Money as integer minor units in your database column. The cast converts between the database integer and a Money object when you read or write model attributes. This keeps storage exact and avoids decimal or float columns for currency amounts.
- How can I format currency amounts in Blade templates?
- The package provides Blade directives and helpers for locale-aware formatting. You can format a Money object directly in a Blade view without manually dividing by 100 or appending symbols. Check the package docs for the exact directive names and locale configuration.
- Does money-for-laravel include validation rules for amounts and currency codes?
- Yes, it ships validation rules for monetary amounts and currency codes. You can use them in form requests or inline validators to reject malformed amounts or unsupported currencies. Combine them with parsing to convert validated input into Money objects.
- Is the Money object immutable and safe for arithmetic?
- Yes, Money objects are immutable, so operations return new instances instead of changing existing values. The package provides fluent arithmetic with precision and overflow protection. This makes calculations predictable and reduces accidental mutation bugs in pricing and invoicing code.
- How do I parse user input or API strings into Money objects?
- The package offers a fluent API for parsing amounts and currency codes into Money objects. You can parse formatted strings, then use the same object for comparisons, arithmetic, and formatting. Always validate raw input with the provided rules before parsing in production flows.
- Can I work with multiple currencies and locale-aware formatting?
- Yes, Money objects are currency-aware and formatting is locale-aware through the Blade helpers and directives. You can keep amounts in different currencies and format them for the user's locale. Be explicit about currency when parsing and comparing to avoid mixing units.
- What are alternatives to money-for-laravel and when should I use this package?
- Alternatives include moneyphp/money and brick/money, which are framework-agnostic money libraries. This package is a good fit when you want native Laravel integration such as Eloquent casts, Blade formatting, validation rules, and a facade. Choose it for Laravel apps that want precise money handling with less glue code.