Skip to main content
Laravel Brick Money provides a seamless integration of the powerful Brick/Money library into your Laravel applications. It offers a type-safe, immutable approach to handling monetary values with proper currency handling, formatting, and arithmetic operations.

What is Laravel Brick Money?

Laravel Brick Money is a Laravel package that wraps the Brick/Money library with Laravel-specific conveniences including:
  • Eloquent model casts for storing money in databases
  • Request macros for handling money input
  • Validation rules for money and currency
  • Blade components and directives
  • Helper functions for quick money creation
  • Livewire synthesizers for seamless integration

Why Use Laravel Brick Money?

Type Safety

Immutable Money objects prevent accidental mutations and provide type-safe monetary calculations with proper rounding.

Currency Aware

Built-in support for 150+ currencies with proper formatting, symbols, and decimal places.

Laravel Integration

Eloquent casts, validation rules, Blade components, and helpers make it feel native to Laravel.

Precision Math

Uses arbitrary precision arithmetic to avoid floating-point errors in financial calculations.

Key Features

Powerful Money Operations

Perform mathematical operations on money values with confidence:
use Devhammed\LaravelBrickMoney\Money;

$price = Money::of(100, 'USD');      // $100.00
$tax = Money::of(10, 'USD');         // $10.00

$total = $price->plus($tax);         // $110.00
$discount = $total->multipliedBy(0.9); // $99.00
$split = $total->split(3);           // [$36.67, $36.67, $36.66]

Flexible Storage Options

Store money in your database using integer (minor units) or decimal (major units):
use Devhammed\LaravelBrickMoney\Casts\AsIntegerMoney;

class Product extends Model
{
    protected function casts(): array
    {
        return [
            'price' => AsIntegerMoney::of('currency'),
        ];
    }
}

Currency Formatting

Automatic formatting based on currency rules:
Money::of(1000, 'USD')->format();  // "$1,000.00"
Money::of(1000, 'EUR')->format();  // "€1.000,00"
Money::of(1000, 'JPY')->format();  // "¥1,000"
Money::of(1000, 'GBP')->format();  // "£1,000.00"

Request Validation

Validate money and currency input with built-in rules:
use Devhammed\LaravelBrickMoney\Rules\MoneyRule;
use Devhammed\LaravelBrickMoney\Rules\CurrencyRule;

public function rules(): array
{
    return [
        'amount' => ['required', new MoneyRule(min: 0, max: 10000)],
        'currency' => ['required', new CurrencyRule()],
    ];
}

Common Use Cases

Handle product prices, shopping carts, order totals, taxes, and discounts with precision. Support multiple currencies for international sales.
Process transactions, calculate interest, handle account balances, and perform currency conversions with accurate arbitrary-precision arithmetic.
Calculate recurring payments, prorate charges, handle upgrades/downgrades, and manage credits with confidence.
Generate invoices with line items, apply taxes, calculate totals, and format amounts according to locale and currency.

Quick Example

Here’s a complete example showing how easy it is to work with money in Laravel:
use Devhammed\LaravelBrickMoney\Money;

// Create money instances
$price = Money::of(99.99, 'USD');
$quantity = 3;

// Perform calculations
$subtotal = $price->multipliedBy($quantity);  // $299.97
$taxRate = 0.08;
$tax = $subtotal->multipliedBy($taxRate);     // $24.00
$total = $subtotal->plus($tax);               // $323.97

// Split payment between 2 people
[$person1, $person2] = $total->split(2);      // [$161.99, $161.98]

// Format for display
echo $total->format();                         // "$323.97"

Browser Support

Laravel Brick Money is a server-side package and works with all Laravel-supported PHP versions (8.2+). The formatted output can be displayed in any browser.

System Requirements

  • PHP 8.2 or higher
  • Laravel 10.x, 11.x, or 12.x
  • Brick/Money 0.10.0 or higher
  • ext-intl (optional, for locale-based formatting)

Next Steps

Installation

Install Laravel Brick Money via Composer and configure it for your application.

Configuration

Learn how to customize default currency settings and configure custom currencies.

Build docs developers (and LLMs) love