helvetitec/laramoney

PHPMoney implementation for Laravel
2,133
Install
composer require helvetitec/laramoney
Latest Version:v1.5.9
Last Updated:Sep 4, 2026
Links: GitHub  ·  Packagist
Maintainer: daredloco

laramoney

MoneyPHP implementation for Laravel

Installation

Install from composer:

composer require helvetitec/laramoney

Usage

  1. Use LaraMoneyCast to cast values to a json field like ['amount' => 100, 'currency' => 'brl']
  2. Use LaraMoneySimpleCast to cast values directly to an integer field with an optional 'currency' field inside the model.
  3. Use Money facade for anything else

LaraMoneyCast

It's easy to store and receive data from the database with the LaraMoneyCast. The value can either be NULL, an array of ['amount', 'currency'], a numeric value or a \Money\Money object.

The database field needs to be a JSON (compatible) field.

Add to the Models cast:

protected $casts = [
    'price' => LaraMoneyCast::class
];

LaraMoneySimpleCast

The simple cast will store the value as a string, not as a JSON object for easier sorting etc. The value can either be NULL, an array of ['amount', 'currency'], a numeric value or a \Money\Money object.

The database field for price and currency needs to be a string.

Add to the Models cast:


protected $fillable = [
    'price',
    'currency' //This is the default field, but can be changed inside the config field 'model_currency_field'.
];

protected $casts = [
    'price' => LaraMoneySimpleCast::class, //Will automatically set the 'currency' field as well
];

Related Packages

gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444