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:
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:
Minor Unit Behavior
Control whether amounts are treated as minor units (cents) by default:
return [
'minor' => env ( 'BRICK_MONEY_MINOR' , false ),
];
When false (default)
When true
// 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:
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
The full name of the currency (e.g., “US Dollar”, “Euro”)
ISO 4217 numeric currency code
Currency symbol (e.g., ”$”, ”€”, ”£”)
Whether the symbol appears before the amount (true) or after (false)
Whether there should be a space between the symbol and amount
Number of decimal places for the currency (e.g., 2 for USD, 0 for JPY)
Character used to separate decimals (e.g., ”.” or ”,”)
Number of digits between thousand separators (usually 3)
Character used to separate thousands (e.g., ”,” or ”.” or space)
Adding Custom Currencies
You can add custom currencies or override existing ones:
Publish Config File
If you haven’t already: php artisan vendor:publish --tag= "brick-money-config"
Add Currency Definition
Add your custom currency to the currencies array: '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' => ',' ,
],
],
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:
Major Currencies
Asian Currencies
Middle Eastern Currencies
Latin American Currencies
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:
Production (.env)
Testing (.env.testing)
Development (.env.local)
BRICK_MONEY_CURRENCY = USD
BRICK_MONEY_MINOR = false
Caching Configuration
In production, cache your configuration for better performance:
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:
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:
<? 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.