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.3(2mo ago)22631[2 PRs](https://github.com/devhammed/laravel-brick-money/pulls)MITPHPPHP ^8.2CI 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 1mo ago

READMEChangelog (4)Dependencies (30)Versions (9)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)

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)
- [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;

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

// Money 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 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": "100",
    "value": "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": ","
    }
}
```

Customize:

```
use Devhammed\LaravelBrickMoney\Money;

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

##### 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
```

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

46

—

FairBetter than 93% of packages

Maintenance89

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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 ~34 days

Total

4

Last Release

61d ago

### 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 (72 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-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

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