PHPackages                             elegantly/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. [Payment Processing](/categories/payments)
4. /
5. elegantly/laravel-money

ActiveLibrary[Payment Processing](/categories/payments)

elegantly/laravel-money
=======================

Use Brick/Money in your Laravel app

v2.3.4(2mo ago)1946.9k—4.3%23MITPHPPHP ^8.1CI failing

Since Nov 20Pushed 1mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (13)Versions (24)Used By (3)

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

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/7c8d8ada3396b2241aec72189132d60a1ff6f4a86cbefdbd99db4ddd2a01ffee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6567616e746c792f6c61726176656c2d6d6f6e65792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elegantly/laravel-money)[![GitHub Tests Action Status](https://camo.githubusercontent.com/dd53b59d1a834a79ac2faad799772de8aff69169ba9719fe917837e5a0a39861/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f456c6567616e74456e67696e656572696e67546563682f6c61726176656c2d6d6f6e65792f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/ElegantEngineeringTech/laravel-money/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/9f848a4ede3f9e3e0009fe6b2ecff0fc67b951c20dca493e920005169cca97ff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c6567616e746c792f6c61726176656c2d6d6f6e65792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elegantly/laravel-money)

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

56

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity40

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 64% 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 ~56 days

Recently: every ~26 days

Total

22

Last Release

88d ago

Major Versions

v0.1.3 → v1.0.02023-02-16

v1.0.4 → v2.0.02024-08-27

### 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 (87 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (28 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (16 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/elegantly-laravel-money/health.svg)

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

###  Alternatives

[finller/laravel-money

Use Brick/Money in your Laravel app

1919.2k](/packages/finller-laravel-money)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[elegantly/laravel-invoices

Store invoices safely in your Laravel application

23131.8k](/packages/elegantly-laravel-invoices)[danestves/laravel-polar

A package to easily integrate your Laravel application with Polar.sh

7812.3k](/packages/danestves-laravel-polar)[musahmusah/laravel-multipayment-gateways

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

852.2k1](/packages/musahmusah-laravel-multipayment-gateways)[elegantly/laravel-translator

All on one translations management for Laravel

6216.9k](/packages/elegantly-laravel-translator)

PHPackages © 2026

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