supplycart / money
Package to handle money operation for supplycart
Requires
- php: ^8.5
- ext-intl: *
- ext-json: *
- brick/money: ^0.14
- illuminate/console: ^13.0
- illuminate/contracts: ^13.0
- illuminate/support: ^13.0
Requires (Dev)
- laravel/pint: ^1.27
- orchestra/canvas: ^11.0
- orchestra/testbench: ^11.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
This package is auto-updated.
Last update: 2026-08-27 05:46:09 UTC
README
A small Laravel 13 value-object package for storing and calculating monetary amounts as integers. It supports configurable precision, currency-aware formatting, Eloquent casting, arithmetic, and tax calculations through a simple contract.
Requirements
- PHP 8.5 or later with
intlandjson - Laravel 13
Installation
composer require supplycart/money php artisan vendor:publish --tag=money-config
The service provider is discovered automatically by Laravel.
Usage
Amounts passed to the constructor or of() are integers in the configured
minor precision:
use Supplycart\Money\Money; $price = Money::of(1_250, 'MYR'); $price->getAmount(); // 1250 $price->getDecimalAmount(); // "12.50" $price->format(); // localized MYR output
Use fromDecimal() when the input is a decimal major-unit value:
$price = Money::fromDecimal('12.50', 'MYR');
Four-decimal storage is supported for calculations that require extra precision:
$price = Money::of(12_500, 'MYR', 4); $price->getDecimalAmount(); // "1.2500"
Eloquent cast
use Illuminate\Database\Eloquent\Model; use Supplycart\Money\Casts\MoneyValue; final class Product extends Model { protected function casts(): array { return [ 'unit_price' => MoneyValue::class, ]; } }
If the model has a currency attribute, the cast uses it. Models may expose a
getDecimalValue() method to select a precision greater than the default two
decimal places.
Tax calculations
Implement Supplycart\Money\Contracts\Tax, attach it with withTax(), then
use getTaxAmount(), afterTax(), or beforeTax().
Development
Run the same quality gates used by CI:
composer lint:check
composer analyse
composer test
composer lint applies Laravel Pint formatting. PHPStan runs at level max.
The reusable coverage checker in scripts/check-coverage.php enforces an 85%
minimum against a Clover report when a coverage driver is available.