Skip to main content

Laravel Brick Money

Type-safe money and currency handling for Laravel applications. Built on Brick/Money for precision arithmetic and proper currency formatting.

Quick Start

Get up and running with Laravel Brick Money in minutes

1

Install the package

Install Laravel Brick Money via Composer:
composer require devhammed/laravel-brick-money
The service provider will be automatically registered via Laravel’s package discovery.
2

Create Money objects

Start working with money values in your application:
use Devhammed\LaravelBrickMoney\Money;
use Devhammed\LaravelBrickMoney\Currency;

// Create money from major units (dollars)
$price = Money::of(100, 'USD');
echo $price; // "$100.00"

// Create money from minor units (cents)
$fee = Money::ofMinor(250, 'USD');
echo $fee; // "$2.50"

// Perform arithmetic operations
$total = $price->plus($fee);
echo $total; // "$102.50"
3

Store in database

Use Eloquent casts to seamlessly store and retrieve money values:
use Illuminate\Database\Eloquent\Model;
use Devhammed\LaravelBrickMoney\Casts\AsIntegerMoney;
use Devhammed\LaravelBrickMoney\Money;

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

$product = Product::create([
    'price' => Money::of(29.99, 'USD'),
    'currency' => 'USD',
]);
4

Display in views

Format money values in Blade templates:
{{-- Using Blade directive --}}
@money($product->price)

{{-- Using Blade component --}}
<x-money :amount="$product->price" />

{{-- Using helper function --}}
{{ money(100, 'EUR') }}

Explore by Topic

Dive deeper into specific features and integrations

Core Concepts

Learn about Money and Currency objects, arithmetic operations, and formatting options.

Eloquent Integration

Store money values in your database using AsIntegerMoney and AsDecimalMoney casts.

HTTP Integration

Work with money in requests, validation rules, and JSON serialization.

Blade Views

Display formatted money values using components, directives, and helpers.

Extensions

Extend Money and Currency classes with custom macros and mixins.

Livewire Support

Use Money and Currency objects in Livewire components with built-in synthesizers.

Key Features

Everything you need for safe money handling in Laravel

Precision Arithmetic

Built on Brick/Money for arbitrary-precision decimal arithmetic. No floating-point errors in financial calculations.

150+ Currencies

Support for all major currencies with proper symbols, decimal places, and formatting rules.

Eloquent Casts

Store money in minor or major units with type-safe model casts for seamless database integration.

Extensible

Add custom methods via macros and mixins to suit your application’s specific needs.

Ready to get started?

Install Laravel Brick Money and start handling money values with confidence in your Laravel applications.

Get Started

Build docs developers (and LLMs) love