PHPackages                             finller/laravel-money - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. finller/laravel-money

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

finller/laravel-money
=====================

Use Brick/Money in your Laravel app

v4.0.0(2mo ago)2022.1k↑275%3[1 PRs](https://github.com/ElegantEngineeringTech/laravel-money/pulls)1MITPHPPHP ^8.1CI passing

Since Nov 20Pushed 1w ago1 watchersCompare

[ Source](https://github.com/ElegantEngineeringTech/laravel-money)[ Packagist](https://packagist.org/packages/finller/laravel-money)[ Docs](https://github.com/ElegantEngineeringTech/laravel-money)[ GitHub Sponsors](https://github.com/ElegantEngineeringTech)[ RSS](/packages/finller-laravel-money/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (26)Versions (29)Used By (1)

Elegant Integration of Brick/Money for Laravel
==============================================

[](#elegant-integration-of-brickmoney-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ae542bfb12e1b850e07ca24306a00ecb3c08011063de8c75a5aed706dd1b92d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6567616e746c792f6c61726176656c2d6d6f6e65792e737667)](https://packagist.org/packages/elegantly/laravel-money)[![Total Downloads](https://camo.githubusercontent.com/9bc116d74c70c9c8c3182a7b31d8c07340b06f9b7e440b6f0207e74284e0d579/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c6567616e746c792f6c61726176656c2d6d6f6e65792e737667)](https://packagist.org/packages/elegantly/laravel-money)[![Tests](https://github.com/ElegantEngineeringTech/laravel-money/actions/workflows/run-tests.yml/badge.svg)](https://github.com/ElegantEngineeringTech/laravel-money/actions/workflows/run-tests.yml)[![Laravel Pint](https://github.com/ElegantEngineeringTech/laravel-money/actions/workflows/pint.yml/badge.svg)](https://github.com/ElegantEngineeringTech/laravel-money/actions/workflows/pint.yml)[![PHPStan](https://github.com/ElegantEngineeringTech/laravel-money/actions/workflows/phpstan.yml/badge.svg)](https://github.com/ElegantEngineeringTech/laravel-money/actions/workflows/phpstan.yml)

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Storing Money in the Database](#storing-money-in-the-database)
- [Usage](#usage)

    - [Casting with a Currency Column (Recommended)](#casting-with-a-currency-column-recommended)
    - [Casting with a Fixed Currency](#casting-with-a-fixed-currency)
    - [Parsing Values](#parsing-values)
    - [Validation Rule](#validation-rule)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

Introduction
------------

[](#introduction)

This package provides seamless, expressive integration of [Brick/Money](https://github.com/brick/money) with Laravel. It enables safe, precise handling of monetary values in your application—using value objects, smart casting, robust parsing, and powerful validation tools.

Features
--------

[](#features)

- **MoneyCast** – Automatically cast Eloquent attributes to `Brick\Money\Money`.
- **MoneyParser** – Convert strings, integers, or floats into `Money` instances safely.
- **ValidMoney Rule** – Validate monetary input with min/max boundaries, type safety, and nullability.

Installation
------------

[](#installation)

Install via Composer:

```
composer require elegantly/laravel-money
```

Configuration
-------------

[](#configuration)

Publish the configuration file if you need to customize defaults:

```
php artisan vendor:publish --tag="money-config"
```

Default config (`config/money.php`):

```
return [
    'default_currency' => 'USD',
];
```

Storing Money in the Database
-----------------------------

[](#storing-money-in-the-database)

For maximum precision, store money using:

- a `bigInteger` column for the amount (in the smallest currency unit)
- a `string` column for the ISO currency code

This avoids floating-point precision issues and ensures accurate calculations.

Example migration:

```
Schema::create('invoices', function (Blueprint $table) {
    $table->id();
    $table->bigInteger('amount');   // e.g., 1000 = $10.00
    $table->string('currency', 3);  // ISO 4217 code
    $table->timestamps();
});
```

Usage
-----

[](#usage)

### Casting with a Currency Column (Recommended)

[](#casting-with-a-currency-column-recommended)

If your model stores both amount and currency, reference the currency column in the cast:

```
use Elegantly\Money\MoneyCast;
use Brick\Money\Money;

/**
 * @property Money $amount
 * @property string $currency
 */
class Invoice extends Model
{

    protected function casts(): array
    {
        return [
            'amount' => MoneyCast::of('currency'),
        ];
    }
}
```

### Casting with a Fixed Currency

[](#casting-with-a-fixed-currency)

If the currency is known and constant, define it directly:

```
use Elegantly\Money\MoneyCast;
use Brick\Money\Money;

/**
 * @property Money $amount
 * @property Money $cost
 */
class Invoice extends Model
{
    protected function casts(): array
    {
        return [
            'cost'  => MoneyCast::of('EUR'),
            'price' => MoneyCast::of('USD'),
        ];
    }
}
```

### Parsing Values

[](#parsing-values)

`MoneyParser` converts common numeric and string formats into `Money` instances:

```
use Elegantly\Money\MoneyParser;

MoneyParser::parse(null, 'EUR');     // null
MoneyParser::parse(110, 'EUR');      // 110.00 €
MoneyParser::parse(100.10, 'EUR');   // 100.10 €
MoneyParser::parse('', 'EUR');       // null
MoneyParser::parse('1', 'EUR');      // 1.00 €
MoneyParser::parse('100.10', 'EUR'); // 100.10 €
```

The parser handles nullability, empty strings, integers, floats, and decimal string formats gracefully.

### Validation Rule

[](#validation-rule)

#### Using `ValidMoney` in Livewire

[](#using-validmoney-in-livewire)

```
namespace App\Livewire;

use Elegantly\Money\Rules\ValidMoney;
use Livewire\Component;

class CustomComponent extends Component
{
    #[Validate([
        new ValidMoney(nullable: false, min: 0, max: 100),
    ])]
    public ?int $price = null;
}
```

#### Using `ValidMoney` in Form Requests

[](#using-validmoney-in-form-requests)

```
namespace App\Http\Requests;

use Elegantly\Money\Rules\ValidMoney;
use Illuminate\Foundation\Http\FormRequest;

class CustomFormRequest extends FormRequest
{
    public function rules()
    {
        return [
            'price' => [
                new ValidMoney(
                    nullable: false,
                    min: 0,
                    max: 100
                ),
            ],
        ];
    }
}
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Changelog
---------

[](#changelog)

See the [CHANGELOG](CHANGELOG.md) for a full history of updates.

Contributing
------------

[](#contributing)

Contributions are welcome! Review the [CONTRIBUTING](CONTRIBUTING.md) file for details.

Security
--------

[](#security)

If you discover a security vulnerability, please refer to the [security policy](../../security/policy).

Credits
-------

[](#credits)

- [Quentin Gabriele](https://github.com/QuentinGab)
- [All Contributors](../../contributors)

License
-------

[](#license)

This package is open-source software released under the MIT License. See [LICENSE.md](LICENSE.md) for details.

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance93

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 67.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~50 days

Recently: every ~18 days

Total

26

Last Release

62d ago

Major Versions

v0.1.3 → v1.0.02023-02-16

v1.0.4 → v2.0.02024-08-27

v2.4.1 → v3.0.02026-05-02

v3.0.0 → v4.0.02026-05-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/d769563728757858e249f266ac2555f28db5640124df92821ed17d93ee76fc7b?d=identicon)[QuentinGab](/maintainers/QuentinGab)

---

Top Contributors

[![QuentinGab](https://avatars.githubusercontent.com/u/40128136?v=4)](https://github.com/QuentinGab "QuentinGab (105 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (29 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (17 commits)")[![BoGnY](https://avatars.githubusercontent.com/u/11542801?v=4)](https://github.com/BoGnY "BoGnY (4 commits)")[![ducpho](https://avatars.githubusercontent.com/u/1398582?v=4)](https://github.com/ducpho "ducpho (1 commits)")

---

Tags

larave-packagelaravelmoneylaravelmoneylaravel-moneyElegantly

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/finller-laravel-money/health.svg)

```
[![Health](https://phpackages.com/badges/finller-laravel-money/health.svg)](https://phpackages.com/packages/finller-laravel-money)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[elegantly/laravel-translator

All on one translations management for Laravel

6333.1k](/packages/elegantly-laravel-translator)[elegantly/laravel-money

Use Brick/Money in your Laravel app

2068.5k12](/packages/elegantly-laravel-money)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
