PHPackages                             devhammed/laravel-brick-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. devhammed/laravel-brick-money

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

devhammed/laravel-brick-money
=============================

Laravel Brick Money Integration

1.0.8(2mo ago)254601MITPHPPHP ^8.3CI passing

Since Dec 3Pushed 1mo agoCompare

[ Source](https://github.com/devhammed/laravel-brick-money)[ Packagist](https://packagist.org/packages/devhammed/laravel-brick-money)[ Docs](https://github.com/devhammed/laravel-brick-money)[ RSS](/packages/devhammed-laravel-brick-money/feed)WikiDiscussions develop Synced today

READMEChangelog (9)Dependencies (46)Versions (13)Used By (0)

Laravel Brick Money
===================

[](#laravel-brick-money)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0c54e23bbdcb1ea93bffbd7c55e4a415c760796f3fb73ff238dc5306a46740a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64657668616d6d65642f6c61726176656c2d627269636b2d6d6f6e65792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/devhammed/laravel-brick-money)[![GitHub Tests Action Status](https://camo.githubusercontent.com/59ca37ad3a37d1fbdc5d475599860390277adb7715f84ffeb4895f3ee8151d87/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64657668616d6d65642f6c61726176656c2d627269636b2d6d6f6e65792f72756e2d74657374732e796d6c3f6272616e63683d646576656c6f70266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/devhammed/laravel-brick-money/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/23acceb8d8230df0b43484806c784f4701924ce872272a4df5b4873bd3f3ae04/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64657668616d6d65642f6c61726176656c2d627269636b2d6d6f6e65792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/devhammed/laravel-brick-money)[![Laravel Compatibility](https://camo.githubusercontent.com/1683bb0d60942249d989ecca315860f9924b27226d7b00492a3ef04ac2a33ca6/68747470733a2f2f62616467652e6c61726176656c2e636c6f75642f62616467652f64657668616d6d65642f6c61726176656c2d627269636b2d6d6f6e6579)](https://packagist.org/packages/devhammed/laravel-brick-money)

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

[](#table-of-contents)

- [Introduction](#introduction)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Available Methods](#available-methods)
    - [Eloquent](#eloquent)
        - [AsIntegerMoney Cast](#asintegermoney-recommended)
        - [AsDecimalMoney Cast](#asdecimalmoney)
        - [AsCurrency Cast](#ascurrency)
    - [HTTP](#http)
        - [Request Macros](#request-macros)
        - [Validation Rules](#validation-rules)
        - [JSON Serialization](#json-serialization)
    - [Helpers](#helpers)
    - [Views](#views)
        - [Components](#components)
        - [Directives](#directives)
    - [Extensions](#extensions)
        - [Macros](#macros)
        - [Mixins](#mixins)
    - [Livewire](#livewire)
    - [Filament](#filament)
        - [Plugin](#plugin)
        - [Forms](#forms)
        - [Tables](#tables)
- [Testing](#testing)
- [Changelog](#changelog)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

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

[](#introduction)

This package provides the Laravel integration of [Brick/Money](https://github.com/brick/money).

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

[](#installation)

Install via Composer:

```
composer require devhammed/laravel-brick-money
```

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

[](#configuration)

Publish the configuration file if you need to customize defaults:

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

You can view the contents of the default configuration in [config/brick-money.php](./config/brick-money.php)

Usage
-----

[](#usage)

```
use Devhammed\LaravelBrickMoney\Money;
use Devhammed\LaravelBrickMoney\Currency;

echo Money::of(100); // '$100.00'

echo Money::of(100, Currency::of('EUR')); // '€100,00'

echo Money::of(100, 'USD'); // '$100.00'

echo Money::ofMinor(100); // '$1.00'

echo Money::ofMinor(100, 'EUR'); // '€1,00'
```

### Available Methods

[](#available-methods)

The package has tried to wrap as many `brick/money` package methods as possible but if you encounter a method that we haven't wrapped yet, you can get the underlying instance by calling `->getMoney()`on `Money` or `->getCurrency()` on `Currency` and call it directly:

```
use Devhammed\LaravelBrickMoney\Money;
use Devhammed\LaravelBrickMoney\Currency;

// Creation
$usd = Currency::of('USD');
$eur = Currency::of('EUR');
$total = Money::of(1000, $usd);
$tax = Money::of(100, $usd);

// Money static methods
Money::of(100, $usd); // Get the Money instance of a numeric amount and currency.
Money::ofMinor(100, $usd); // Get the Money instance of a numeric amount in minor units and currency.
Money::ofMoney(\Brick\Money\Money::of(100, 'USD')); // Get the Money instance of a Brick\Money\Money instance.
Money::zero($usd); // Get the Money instance of zero amount and currency.
Money::min(Money::of(100, $usd), Money::of(200, $usd)); // Get the minimum of two or more Money instances.
Money::max(Money::of(100, $usd), Money::of(200, $usd)); // Get the maximum of two or more Money instances.
Money::total(Money::of(100, $usd), Money::of(200, $usd)); // Get the total of two or more Money instances.
Money::avg(Money::of(100, $usd), Money::of(200, $usd)); // Get the average of two or more Money instances.
Money::locale('en_US'); // Get or set the default locale for formatting.
Money::jsonSerializeMinorUnits(true); // Get or set whether to return minor units in JSON serialization.
Money::jsonSerializer(fn(Money $money) => [
    'amount' => (string) (Money::jsonSerializeMinorUnits() ?
    $money->getMinorAmount() : $money->getAmount(),
    'currency' => (string) $money->getCurrency(),
 ); // Get or set the JSON serializer for Money instances.

// Money instance methods
$total->getCurrency(); // Devhammed\LaravelBrickMoney\Currency{}
$total->getMoney(); // Brick\Money\Money{}
$total->getContext(); // Brick\Money\Context\DefaultContext{}
$total->getAmount(); // Brick\Math\BigDecimal{}
$total->getMinorAmount(); // Brick\Math\BigDecimal{}
$total->getUnscaledAmount(); // Brick\Math\BigInteger{}
$total->getSign(); // 1
$total->isZero(); // false
$total->isNegative(); // false
$total->isNegativeOrZero(); // false
$total->isPositive(); // true
$total->isPositiveOrZero(); // true
$total->compareTo($tax); // 1
$total->isEqualTo($tax); // false
$total->isLessThan($tax); // false
$total->isLessThanOrEqualTo($tax); // false
$total->isGreaterThan($tax); // true
$total->isGreaterThanOrEqualTo($tax); // true
$total->plus($tax); // $1,100
$total->minus($tax); // $900
$total->multipliedBy(2); // $2,000
$total->dividedBy(2); // $500
$total->allocate(1, 2, 3);
$total->split(2); // [$500, $500]
$total->splitWithRemainder(3); // [$33.33, $33.33, $33.33, $0.01]
$total->abs(); // $1,000
$total->convertedTo($eur, 0.91); // $910
$total->convertedTo('NGN', 1457); // N1,457,000
$total->negated(); // -$1,000
$total->format(); // "$1,000"

# Currency static methods
Currency::of('USD'); // Get the Currency instance of a currency code.
Currency::of(\Brick\Money\Currency::of('USD')); // Get the Currency instance of a Brick\Money\Currency instance.
Currency::ofCountry('NG'); // Get the Currency instance for a country code.
Currency::currencies(); // Get an array of all configured currencies.
Currency::jsonSerializer(fn(Currency $currency) => [
    'name' => $currency->getName(),
    'code' => $currency->getCode(),
]); // Get or set the JSON serializer for Currency instances.

# Currency instance methods
$usd->getCode(); // "USD"
$usd->getName(); // "US Dollar"
$usd->getNumericCode(); // 840
$usd->getSymbol(); // $
$usd->isSymbolFirst(); // true
$usd->isSymbolSpaced(); // false
$usd->getDecimalPlaces(); // 2
$usd->getDecimalSeparator(); // "."
$usd->getThousandPlaces(); // 3
$usd->getThousandSeparator(); // ","
$usd->getCurrency(); // Brick\Money\Currency{}
$usd->is($eur); // false
```

### Eloquent

[](#eloquent)

This package provides Model casts to help with money and currency storage in the database.

There are currently two supported storage cast types, and each of them support either storing in a single JSON column or separate amount and currency columns:

#### `AsIntegerMoney` (Recommended)

[](#asintegermoney-recommended)

This stores the amount in the currency's minor unit.

Example Model:

```
use Devhammed\LaravelBrickMoney\Money;
use Devhammed\LaravelBrickMoney\Casts\AsIntegerMoney;

/**
 * @property Money $amount
 * @property string $currency
 * @property Money $tax
 */
class Transaction extends Model
{
    protected function casts(): array
    {
        return [
            'amount' => AsIntegerMoney::of('currency'),
            'tax' => AsIntegerMoney::class,
        ];
    }
}
```

Example Migration:

```
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;

Schema::create('transactions', function (Blueprint $table) {
    $table->id();

    $table->bigInteger('amount');   // e.g., 1000 = $10.00,
    $table->string('currency');  // currency code e.g. USD
    $table->json('tax'); // {"amount": "2345", "currency": "TRX"}

    $table->timestamps();
});
```

> Some cryptocurrencies, particularly those with very high precision (e.g., ETH uses 18 decimal places) will exceed the limit of `->bigInteger()` so it is recommended to use `->string()` in this case when you are using the separate columns mode.

#### `AsDecimalMoney`

[](#asdecimalmoney)

This stores the amount in the currency's major unit.

Example Model:

```
use Devhammed\LaravelBrickMoney\Money;
use Devhammed\LaravelBrickMoney\Casts\AsDecimalMoney;

/**
 * @property Money $amount
 * @property string $currency
 * @property Money $tax
 */
class Transaction extends Model
{
    protected function casts(): array
    {
        return [
            'amount' => AsDecimalMoney::of('currency'),
            'tax' => AsDecimalMoney::class,
        ];
    }
}
```

Example Migration:

```
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;

Schema::create('transactions', function (Blueprint $table) {
    $table->id();

    $table->decimal('amount', 36, 18);  // e.g., 10.00 = $10.00,
    $table->string('currency');  // currency code e.g. USD
    $table->json('tax'); // {"amount": "23.45", "currency": "TRX"}

    $table->timestamps();
});
```

> The reason for using `DECIMAL(36, 18)` in the separate column example is to accommodate cryptocurrencies with very high precision like ETH that uses 18 decimal places, you can reduce or increase the scale and precision to match your project requirements.

#### `AsCurrency`

[](#ascurrency)

This is useful for casting currency columns to `Currency`.

Example Model:

```
use Devhammed\LaravelBrickMoney\Currency;
use Devhammed\LaravelBrickMoney\Casts\AsCurrency;

/**
 * @property Currency $currency
 */
class Transaction extends Model
{
    protected function casts(): array
    {
        return [
            'currency' => AsCurrency::class,
        ];
    }
}
```

Example Migration:

```
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;

Schema::create('transactions', function (Blueprint $table) {
    $table->id();
    $table->string('currency');  // currency code e.g. USD
    $table->timestamps();
});
```

> This can also be used in conjunction with the currency column of the amount casts explained above.

### HTTP

[](#http)

This package provides request macros and validation rules to work with `money`/`currency` in HTTP Requests.

#### Request Macros

[](#request-macros)

```
request()->currency('currency'); // Devhammed\LaravelBrickMoney\Currency{}

request()->money('price'); // Devhammed\LaravelBrickMoney\Money{}

request()->money('price', currency: 'EUR', minor: true); // Devhammed\LaravelBrickMoney\Money{}
```

#### Validation Rules

[](#validation-rules)

```
namespace App\Http\Requests;

use Devhammed\LaravelBrickMoney\Rules\MoneyRule;
use Devhammed\LaravelBrickMoney\Rules\CurrencyRule;
use Illuminate\Foundation\Http\FormRequest;

class CreateProductRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'price' => [
                'required',
                new MoneyRule(
                    min: 0,
                    max: 1000,
                ),
            ],
            'currency' => [
                'required',
                new CurrencyRule(),
            ],
        ];
    }
}
```

#### JSON Serialization

[](#json-serialization)

This package provides JSON serialization for both `Money` and `Currency` objects but you can customize according to your project requirements.

##### Money

[](#money)

Default:

```
{
    "amount": "1.00",
    "currency": {
        "name": "US Dollar",
        "code": "USD",
        "numeric_code": 840,
        "symbol": "$",
        "symbol_first": true,
        "symbol_spaced": false,
        "decimal_places": 2,
        "decimal_separator": ".",
        "thousand_places": 3,
        "thousand_separator": ","
    }
}
```

The `amount` field respects the JSON serialization unit of the `Money` object (which defaults to `brick-money.minor` configuration). If set to `true`, the amount is returned in minor units (e.g., cents for USD). Otherwise, it is returned in major units (e.g., dollars for USD):

```
use Devhammed\LaravelBrickMoney\Money;

Money::jsonSerializeMinorUnits(true); // or `false` to return major units.
```

You can also customize the whole JSON serialization process by providing a custom serializer:

```
use Devhammed\LaravelBrickMoney\Money;

Money::jsonSerializer(fn(Money $money) => [
    'amount' => (string) (Money::jsonSerializeMinorUnits() ? $money->getMinorAmount() : $money->getAmount()),
    'currency' => (string) $money->getCurrency(),
]);
```

Which will return something like this:

```
{
    "amount": "1.00",
    "currency": "USD"
}
```

##### Currency

[](#currency)

Default:

```
{
    "name": "US Dollar",
    "code": "USD",
    "numeric_code": 840,
    "symbol": "$",
    "symbol_first": true,
    "symbol_spaced": false,
    "decimal_places": 2,
    "decimal_separator": ".",
    "thousand_places": 3,
    "thousand_separator": ","
}
```

Customize:

```
use Devhammed\LaravelBrickMoney\Currency;

Currency::jsonSerializer(fn(Currency $currency) => [
    'name' => $currency->getName(),
    'code' => $currency->getCode(),
]);
```

### Helpers

[](#helpers)

```
money(100) // $100.00

money(100, minor: true) // $1.00

money(100, 'EUR') // €100,00

currency('USD') // USD
```

### Views

[](#views)

This package provides helpers to work with `money` and `currency` in Blade templates.

#### Components

[](#components)

```

```

#### Directives

[](#directives)

```
@money(100) // $100.00

@money(100, minor: true) // $1.00

@money(100, 'EUR') // €100,00

@currency('USD') // USD
```

### Extensions

[](#extensions)

The `Money` and `Currency` classes implements the Laravel `Macroable` trait, allowing you to add custom functionalities through macros and mixins.

#### Macros

[](#macros)

```
use Devhammed\LaravelBrickMoney\Money;
use Devhammed\LaravelBrickMoney\Currency;

Money::macro('zero', fn(Currency|string $currency) => Money::of(0, $currency));

Money::macro('withPercentage', function (float $percentage): Money {
    return $this->multipliedBy(1 + ($percentage / 100));
});

Money::zero('USD')->plus(100)->withPercentage(10); // $110
```

#### Mixins

[](#mixins)

And with mixins, you can achieve the same thing using a dedicated class:

```
use Devhammed\LaravelBrickMoney\Money;
use Devhammed\LaravelBrickMoney\Currency;

class MoneyExtensions
{
    public static function zero(Currency|string $currency): Money
    {
        return Money::of(0, $currency);
    }

    public function withPercentage(float $percentage): Money
    {
        return $this->multipliedBy(1 + ($percentage / 100));
    }
}

Money::mixin(new MoneyExtensions());

Money::zero('USD')->plus(100)->withPercentage(10); // $110
```

Livewire
--------

[](#livewire)

This package provides automatic support for [Livewire](https://livewire.laravel.com/) by registering property synthesizers for `Money` and `Currency` objects.

This allows you to use `Money` and `Currency` objects directly as Livewire properties:

```
use Devhammed\LaravelBrickMoney\Money;
use Livewire\Component;

class Wallet extends Component
{
    public Money $balance;

    public function mount()
    {
        $this->balance = Money::of(100, 'USD');
    }

    public function addTenDollars()
    {
        $this->balance = $this->balance->plus(10);
    }

    public function render()
    {
        return view('livewire.wallet');
    }
}
```

Filament
--------

[](#filament)

This package also provides a [Filament](https://filamentphp.com/) plugin and components to work with money and currency.

### Forms

[](#forms)

The `MoneyInput` component allows you to manage money fields in your Filament forms. It provides a fused group of an amount input and a currency selector.

```
use Devhammed\LaravelBrickMoney\Filament\Forms\Components\MoneyInput;

MoneyInput::for('price')
```

It will automatically use the configured currencies and default currency to populate the currency selector.

> You must not use the `make()` method on the `MoneyInput` class directly, as we extended the `FusedGroup` component to provide this functionality and PHP does not support overriding methods with different signatures.

You can also specify a custom list of currencies and a default currency:

```
use Devhammed\LaravelBrickMoney\Filament\Forms\Components\MoneyInput;

MoneyInput::for('price')
    ->defaultCurrency('USD')
    ->currencies(['USD' => 'US Dollar', 'EUR' => 'Euro'])
```

You can also fix the currency so only the amount is editable:

```
MoneyInput::for('price')
    ->fixedCurrency()
```

And you can customize the underlying input and select components:

```
MoneyInput::for('price')
    ->currencySelect(fn ($select) => $select->columnSpan(['xl' => 3]))
    ->amountInput(fn ($input) => $input->columnSpan(['xl' => 9]))
```

### Tables

[](#tables)

The `MoneyColumn` allows you to display money values in your Filament tables.

```
use Devhammed\LaravelBrickMoney\Filament\Tables\Columns\MoneyColumn;

MoneyColumn::make('price')
```

It will automatically format the `Money` object using its `format()` method, and it extended the `TextColumn` component so you can use any of its methods to further customize the column.

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Changelog
---------

[](#changelog)

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

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Hammed Oyedele](https://github.com/devhammed)
- [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

48

—

FairBetter than 93% of packages

Maintenance87

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.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 ~19 days

Recently: every ~8 days

Total

8

Last Release

76d ago

PHP version history (2 changes)1.0.0PHP ^8.2

1.0.5PHP ^8.3

### Community

Maintainers

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

---

Top Contributors

[![devhammed](https://avatars.githubusercontent.com/u/22827908?v=4)](https://github.com/devhammed "devhammed (108 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

bricklaravelmoneylaravelmoneybrick

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/devhammed-laravel-brick-money/health.svg)](https://phpackages.com/packages/devhammed-laravel-brick-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)

PHPackages © 2026

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