Skip to main content
Laravel Brick Money works out of the box with sensible defaults, but you can customize its behavior by publishing and modifying the configuration file.

Publishing the Config File

Publish the configuration file to your application:
php artisan vendor:publish --tag="brick-money-config"
This creates a config/brick-money.php file in your application with all available configuration options.
You only need to publish the config file if you want to customize the default behavior. The package works perfectly fine with the built-in defaults.

Configuration Options

The configuration file contains the following main sections:

Default Currency

Set the default currency for your application:
config/brick-money.php
return [
    'currency' => env('BRICK_MONEY_CURRENCY', 'USD'),
];
This currency is used when you create money instances without specifying a currency:
// Uses the default currency from config
echo money(100)->format();           // "$100.00" (if USD)
echo currency()->getCode();          // "USD"
Set BRICK_MONEY_CURRENCY in your .env file to change the default currency without modifying code:
.env
BRICK_MONEY_CURRENCY=EUR

Minor Unit Behavior

Control whether amounts are treated as minor units (cents) by default:
config/brick-money.php
return [
    'minor' => env('BRICK_MONEY_MINOR', false),
];
// Amount is treated as major units (dollars)
money(100)->format();  // "$100.00"
Changing this setting affects all uses of the money() helper function that don’t explicitly specify the minor parameter. Be careful when modifying this in existing applications.

Currency Definitions

The config file includes definitions for 150+ currencies with all necessary metadata:
config/brick-money.php
return [
    'currencies' => [
        'USD' => [
            'name' => 'US Dollar',
            'numeric_code' => 840,
            'symbol' => '$',
            'symbol_first' => true,
            'symbol_spaced' => false,
            'decimal_places' => 2,
            'decimal_separator' => '.',
            'thousand_places' => 3,
            'thousand_separator' => ',',
        ],
        
        'EUR' => [
            'name' => 'Euro',
            'numeric_code' => 978,
            'symbol' => '€',
            'symbol_first' => true,
            'symbol_spaced' => false,
            'decimal_places' => 2,
            'decimal_separator' => ',',
            'thousand_places' => 3,
            'thousand_separator' => '.',
        ],
        
        // ... 150+ more currencies
    ],
];

Currency Properties Explained

name
string
required
The full name of the currency (e.g., “US Dollar”, “Euro”)
numeric_code
integer
required
ISO 4217 numeric currency code
symbol
string
required
Currency symbol (e.g., ”$”, ”€”, ”£”)
symbol_first
boolean
required
Whether the symbol appears before the amount (true) or after (false)
symbol_spaced
boolean
required
Whether there should be a space between the symbol and amount
decimal_places
integer
required
Number of decimal places for the currency (e.g., 2 for USD, 0 for JPY)
decimal_separator
string
required
Character used to separate decimals (e.g., ”.” or ”,”)
thousand_places
integer
required
Number of digits between thousand separators (usually 3)
thousand_separator
string
required
Character used to separate thousands (e.g., ”,” or ”.” or space)

Adding Custom Currencies

You can add custom currencies or override existing ones:
1

Publish Config File

If you haven’t already:
php artisan vendor:publish --tag="brick-money-config"
2

Add Currency Definition

Add your custom currency to the currencies array:
config/brick-money.php
'currencies' => [
    // Existing currencies...
    
    'BTC' => [
        'name' => 'Bitcoin',
        'numeric_code' => 0,
        'symbol' => '₿',
        'symbol_first' => true,
        'symbol_spaced' => false,
        'decimal_places' => 8,
        'decimal_separator' => '.',
        'thousand_places' => 3,
        'thousand_separator' => ',',
    ],
    
    'CREDITS' => [
        'name' => 'Game Credits',
        'numeric_code' => 0,
        'symbol' => 'CR',
        'symbol_first' => false,
        'symbol_spaced' => true,
        'decimal_places' => 0,
        'decimal_separator' => '',
        'thousand_places' => 3,
        'thousand_separator' => ',',
    ],
],
3

Use Custom Currency

Use your custom currency like any other:
$bitcoin = Money::of(0.5, 'BTC');
echo $bitcoin->format();  // "₿0.50000000"

$credits = Money::of(1000, 'CREDITS');
echo $credits->format();  // "1,000 CR"
Custom currencies are useful for cryptocurrencies, loyalty points, in-game currencies, or any custom monetary system your application needs.

Built-in Currency Examples

Here are examples of various built-in currencies and their formatting:
Money::of(1234.56, 'USD')->format();  // "$1,234.56"
Money::of(1234.56, 'EUR')->format();  // "€1.234,56"
Money::of(1234.56, 'GBP')->format();  // "£1,234.56"
Money::of(1234.56, 'JPY')->format();  // "¥1,235" (no decimals)

Environment-Specific Configuration

Use environment variables to configure different currencies per environment:
BRICK_MONEY_CURRENCY=USD
BRICK_MONEY_MINOR=false

Caching Configuration

In production, cache your configuration for better performance:
php artisan config:cache
After caching, the env() helper will return null. Make sure all environment-specific values are defined in the config file with env() fallbacks.
Clear the cache after configuration changes:
php artisan config:clear

Programmatic Currency Registration

You can also register currencies programmatically in a service provider:
app/Providers/AppServiceProvider.php
use Devhammed\LaravelBrickMoney\Currency;

public function boot(): void
{
    Currency::currencies([
        'POINTS' => [
            'name' => 'Loyalty Points',
            'numeric_code' => 0,
            'symbol' => 'PTS',
            'symbol_first' => false,
            'symbol_spaced' => true,
            'decimal_places' => 0,
            'decimal_separator' => '',
            'thousand_places' => 3,
            'thousand_separator' => ',',
        ],
    ]);
}

Complete Configuration Example

Here’s a complete example configuration file:
config/brick-money.php
<?php

return [
    // Default currency code (ISO 4217)
    'currency' => env('BRICK_MONEY_CURRENCY', 'USD'),
    
    // Treat amounts as minor units by default
    'minor' => env('BRICK_MONEY_MINOR', false),
    
    // Currency definitions
    'currencies' => [
        'USD' => [
            'name' => 'US Dollar',
            'numeric_code' => 840,
            'symbol' => '$',
            'symbol_first' => true,
            'symbol_spaced' => false,
            'decimal_places' => 2,
            'decimal_separator' => '.',
            'thousand_places' => 3,
            'thousand_separator' => ',',
        ],
        
        // Add more currencies as needed...
    ],
];

Next Steps

Core Concepts

Learn how to create and format Money objects in your application.

Eloquent Integration

Store money values in your database using Eloquent casts.

Build docs developers (and LLMs) love