Overview
Laravel Brick Money provides custom Blade directives that offer a concise syntax for rendering formatted monetary values and currency information. These directives are ideal for inline usage where the component syntax might be too verbose.
@money Directive
The @money directive renders formatted monetary values with automatic currency formatting.
Basic Usage
Basic Amount
With Currency
Minor Units
Full Parameters
@money ( 100 )
{{-- Output: $100.00 --}}
Parameters
amount
BigNumber|float|int|string
required
The monetary amount to display. Can be a number, string, or BigNumber instance.
currency
string
default: "config('brick-money.currency')"
The currency code (e.g., “USD”, “EUR”, “GBP”). Defaults to the configured currency in your brick-money.php config file.
minor
bool
default: "config('brick-money.minor')"
Whether the amount is in minor units (e.g., cents). When true, an amount of 100 represents 1.00 i n s t e a d o f 1.00 instead of 1.00 in s t e a d o f 100.00. Defaults to the configured value in your brick-money.php config file.
A Brick\Money\Context instance for custom precision handling. Advanced use cases only.
roundingMode
RoundingMode
default: "RoundingMode::UNNECESSARY"
The rounding mode to use from Brick\Math\RoundingMode.
Examples
Product Listing
Invoice Totals
Transaction History
Inline Calculations
< div class = "product-grid" >
@foreach ( $products as $product )
< div class = "product-card" >
< h3 > {{ $product -> name }} </ h3 >
< p class = "price" > @money ( $product -> price , $product -> currency ) </ p >
</ div >
@endforeach
</ div >
< table class = "invoice" >
< tr >
< td > Subtotal: </ td >
< td > @money ( $invoice -> subtotal , 'USD' ) </ td >
</ tr >
< tr >
< td > Tax ( {{ $invoice -> tax_rate }} %): </ td >
< td > @money ( $invoice -> tax , 'USD' ) </ td >
</ tr >
< tr >
< td > Shipping: </ td >
< td > @money ( $invoice -> shipping , 'USD' ) </ td >
</ tr >
< tr class = "total" >
< th > Total: </ th >
< th > @money ( $invoice -> total , 'USD' ) </ th >
</ tr >
</ table >
< ul class = "transaction-list" >
@foreach ( $transactions as $transaction )
< li >
< span class = "date" > {{ $transaction -> date }} </ span >
< span class = "description" > {{ $transaction -> description }} </ span >
< span class = "amount {{ $transaction -> type }} " >
@if ( $transaction -> type === 'credit' )
+ @money ( $transaction -> amount_cents , $transaction -> currency , minor : true )
@else
- @money ( $transaction -> amount_cents , $transaction -> currency , minor : true )
@endif
</ span >
</ li >
@endforeach
</ ul >
< div class = "pricing-breakdown" >
< p > Base Price: @money ( $basePrice , 'USD' ) </ p >
< p > With 10% discount: @money ( $basePrice * 0.9 , 'USD' ) </ p >
< p > With tax: @money ( $basePrice * 1.08 , 'USD' ) </ p >
</ div >
Using with Dynamic Variables
{{-- Pass variables directly --}}
@money ( $amount , $currencyCode )
{{-- Use object properties --}}
@money ( $order -> total , $order -> currency )
{{-- With named parameters --}}
@money ( $price , currency : 'EUR' , minor : false )
{{-- Mix positional and named parameters --}}
@money ( $cents , 'USD' , minor : true )
@currency Directive
The @currency directive renders formatted currency information.
Basic Usage
@currency ( 'USD' )
{{-- Output: USD --}}
Parameters
currency
string
default: "config('brick-money.currency')"
The currency code to display (e.g., “USD”, “EUR”, “GBP”). If not provided, uses the default currency from configuration.
Examples
Display Currency
Currency List
Multi-Currency Display
Default Currency
< div class = "account-summary" >
< h2 > Account Balance </ h2 >
< p class = "balance" > @money ( $balance , $currency ) </ p >
< p class = "currency" > Currency: @currency ( $currency ) </ p >
</ div >
< ul class = "supported-currencies" >
@foreach ([ 'USD' , 'EUR' , 'GBP' , 'JPY' ] as $code )
< li >
@currency ( $code ) - {{ currency ( $code ) -> getName () }}
</ li >
@endforeach
</ ul >
< table class = "exchange-rates" >
< thead >
< tr >
< th > From </ th >
< th > To </ th >
< th > Rate </ th >
< th > Amount </ th >
</ tr >
</ thead >
< tbody >
@foreach ( $rates as $rate )
< tr >
< td > @currency ( $rate -> from ) </ td >
< td > @currency ( $rate -> to ) </ td >
< td > {{ $rate -> rate }} </ td >
< td > @money ( $rate -> amount , $rate -> to ) </ td >
</ tr >
@endforeach
</ tbody >
</ table >
{{-- Uses config('brick-money.currency') if no parameter provided --}}
< p > Default currency: @currency () </ p >
{{-- Equivalent to: --}}
< p > Default currency: @currency ( config ( 'brick-money.currency' )) </ p >
Implementation Details
Both directives are registered in the package service provider and compile down to simple PHP echo statements:
// src/Provider.php
Blade :: directive ( 'money' , function ( string $expression ) {
return "<?php echo money({ $expression }); ?>" ;
});
Blade :: directive ( 'currency' , function ( string $expression ) {
return "<?php echo currency({ $expression }); ?>" ;
});
Compiled Output
When Blade compiles your templates, the directives are transformed:
Before Compilation
After Compilation
@money ( 100 , 'USD' )
@currency ( 'EUR' )
The directives directly call the money() and currency() helper functions under the hood. This means they support all the same parameters and behavior as the helper functions.
Directive vs Component
Choose between directives and components based on your use case:
Feature Directive Component Syntax @money(100)<x-money amount="100" />Inline usage ✓ Excellent ✗ More verbose Readability Good for simple cases Better for complex attributes IDE support Limited Better autocomplete Best for Quick inline formatting Complex layouts with many attributes
When to Use Directives
{{-- Inline within text --}}
< p > Your balance is @money ( $balance ) as of {{ $date }} </ p >
{{-- Simple table cells --}}
< td > @money ( $price , 'USD' ) </ td >
{{-- List items --}}
< li > Total: @money ( $total ) </ li >
When to Use Components
{{-- Multiple attributes --}}
< x-money
:amount = " $amount "
currency = "USD"
:minor = " true "
:context = " $customContext "
/>
{{-- Within component-heavy templates --}}
< x-card >
< x-card-title > {{ $product -> name }} </ x-card-title >
< x-card-price >
< x-money :amount = " $product -> price " :currency = " $product -> currency " />
</ x-card-price >
</ x-card >