Skip to content

Helpers & Blade

Global functions, autoloaded with the package. Each one calls the currency binding, so they follow the current provider and base currency.

currency_convert(100, 'USD', 'EUR'); // Currency::convert()
currency_convert(100, 'USD', 'EUR', 'sell');
currency_convert_at(100, 'USD', 'UAH', '2024-01-15'); // Currency::convertAt(); a string or DateTimeInterface
currency_convert_at(100, 'USD', 'UAH', now()->subMonth());
currency_format(1234.56, 'USD'); // "$ 1,234.56"
currency_format(1234.56, 'USD', false); // "1,234.56"
currency_rate('USD'); // Currency::getRate(), ?float
currency_rate('USD', 'buy');
currency_symbol('USD'); // '$'; the code itself if not configured

Signatures — Currency facade reference. Every helper is declared only if a function with that name doesn’t exist yet. There are no helpers for getRateAt() / getRatesAt().

@currency(100, 'USD', 'EUR') {{-- convert(), prints the float: 92.47 --}}
@currency($price, 'UAH', 'USD', 'sell')
@currencyFormat(1234.56, 'USD') {{-- format(): $ 1,234.56 --}}
@currencyFormat($price, 'USD', false)
@currencyRate('USD') {{-- getRate(): 41.5 --}}
@currencyRate('USD', 'buy')
@currencySymbol('USD') {{-- $ --}}

The arguments are passed to the method as is, so every optional argument of the method is accepted.

For full control use the facade in Blade:

{{ Currency::format(Currency::convert($product->price, 'UAH', $userCurrency), $userCurrency) }}