Weave 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
Laravel Currency Casting

Laravel Currency Casting Laravel Package

snoeren-development/laravel-currency-casting

Laravel Currency Casting provides an Eloquent cast that stores monetary values as integers and exposes them as currency-aware objects, so you can format, convert, and calculate prices cleanly across your models without scattering money-handling logic throughout your application.

View on GitHub
Deep Wiki
Context7

Laravel Currency Casting adds a money-aware Eloquent cast to your models, so currency attributes are stored predictably and exposed as rich, formatted values instead of raw floats. Define a cast on any monetary column and let the package handle conversion, precision, and display, keeping pricing logic clean and consistent across your application.

  • Eloquent cast for currency attributes with configurable precision
  • Automatic conversion between stored amounts and money values
  • Formatting helpers for localized, currency-aware output
  • Consistent precision to avoid floating-point rounding issues
Frequently asked questions about Laravel Currency Casting
How do I install the laravel-currency-casting package in a Laravel app?
Install it with Composer using the package name snoeren-development/laravel-currency-casting. Laravel's package auto-discovery registers the service provider, so you normally do not need to add anything to config/app.php. After that, add the cast to the $casts array of any model that has a monetary attribute. Check the repository README for any optional publish or configuration steps that apply to your version.
How does the currency cast store monetary values in the database?
Amounts are persisted as integers in minor units, so a price of 12.34 is stored as 1234 rather than as a floating point number. The cast then exposes that column as a currency object (or float) inside your model, so application code works with readable values while the database keeps exact integers. Use an integer or bigInteger column in your migration and never a float or double column. Integer storage avoids the rounding drift you get when binary floats represent decimal money.
Does laravel-currency-casting support Laravel 13?
Yes. Version 1.11.0 is a compatibility release that adds support for Laravel 13. It contains no feature or breaking-change signal beyond widening the framework constraint plus the matching test matrix. Confirm in composer.json whether Laravel 13 was added alongside Laravel 11 and 12 or in place of them before you plan an upgrade.
Does version 1.11.0 still support Laravel 11 and 12?
The release notes only state that Laravel 13 support was added, so the constraint is either additive (11, 12 and 13 in the same line) or narrowed to 13 only. If it narrows, applications on Laravel 11 or 12 stay on v1.10.x and stop receiving fixes on that branch. Ask the maintainer directly about the support window for Laravel 12 and whether security patches will be backported.
What PHP version does laravel-currency-casting require on Laravel 13?
The PHP floor normally tracks the framework you run, because Laravel 13 may raise its own minimum PHP version. Check the require block in the package's composer.json and compare it with the PHP version in your Docker base image, CI image and static analysis config. A raised floor cascades across your estate even though the package itself is not at fault. If your runtime image is older than the declared floor, Composer will refuse the install.
How do I format a cast currency attribute in Blade or an API response?
The cast gives you a currency object instead of a raw integer, so you call its formatting methods directly in Blade or a controller. For JSON APIs, convert the value explicitly in an API resource or accessor rather than relying on the default model serialisation. Doing the conversion at the boundary keeps your output consistent if the package's serialisation behaviour changes. Keep the underlying integer column untouched when you only need a display string.
Can I do arithmetic on cast currency values without floating point errors?
Yes, that is the point of storing minor units. Because the database holds exact integers and the package exposes currency objects that support arithmetic, totals and conversions, you avoid the accumulation errors that come from summing floats. Do the maths through the currency object or in minor units, then persist the integer result. Round only once, at the point where you present or store the final amount.
How should I test Eloquent models that use the currency cast?
Use an in-memory SQLite database or your normal test connection with the real migration so the integer column type is exercised. Assert the raw attribute equals the expected minor units and assert the cast output and formatted string separately. Add a feature test in the host application that reads and writes a monetary attribute, since that is the only reliable proof the cast behaves identically after a Laravel major upgrade.
Is laravel-currency-casting safe for production invoice and price totals?
Storing money as integer minor units in integer columns is the standard safe approach, and that is what this package assumes. Watch three things in production: define a rounding policy for multi-currency conversions, keep the currency code stored alongside the amount, and pin the package version so an upgrade cannot silently change casting behaviour. Run your application's own integration tests against the pinned version before deploying a framework major.
What are the alternatives to a currency cast package in Laravel?
You can write your own accessor and mutator pair around an integer column, which is fine for a single currency and no conversion logic. For richer needs, libraries such as moneyphp/money or brick/money give you value objects, currency handling and formatting without tying the behaviour to Eloquent. This package mainly saves boilerplate by wiring that behaviour straight into the model's casts. Pick based on how much multi-currency and conversion logic your application actually needs.
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.
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle