Skip to main content

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

@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.00insteadof1.00 instead of 100.00. Defaults to the configured value in your brick-money.php config file.
context
Context
default:"null"
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

<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>

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

<div class="account-summary">
    <h2>Account Balance</h2>
    <p class="balance">@money($balance, $currency)</p>
    <p class="currency">Currency: @currency($currency)</p>
</div>

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:
@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:
FeatureDirectiveComponent
Syntax@money(100)<x-money amount="100" />
Inline usage✓ Excellent✗ More verbose
ReadabilityGood for simple casesBetter for complex attributes
IDE supportLimitedBetter autocomplete
Best forQuick inline formattingComplex 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>

Build docs developers (and LLMs) love