Skip to main content
Currencies define the monetary units available for pricing, with exchange rates for conversion.

Overview

Currencies allow pricing to be managed in different monetary units. Each currency has an exchange rate relative to the default currency, enabling price conversion.
Lunar\Models\Currency

Fields

FieldTypeDescription
ididPrimary key
codestringThe ISO 4217 currency code
namestringA descriptive name for the currency
exchange_ratedecimal(10,4)The exchange rate relative to the default currency
decimal_placesintegerThe number of decimal places, e.g. 2
enabledbooleanWhether the currency is enabled
defaultbooleanWhether the currency is the default
sync_pricesbooleanWhether to synchronize prices for this currency
created_attimestamp
updated_attimestamp

Relationships

RelationshipTypeRelated ModelDescription
pricesHasManyLunar\Models\PricePrices in this currency

Scopes

ScopeDescription
enabled($enabled = true)Filter to enabled/disabled currencies
default($default = true)Filter to the default currency

Creating a currency

use Lunar\Models\Currency;

Currency::create([
    'code' => 'GBP',
    'name' => 'British Pound',
    'exchange_rate' => 1.0000,
    'decimal_places' => 2,
    'enabled' => true,
    'default' => true,
]);

Exchange rates

Exchange rates are relative to the default currency. For example, given the following default currency:
use Lunar\Models\Currency;

Currency::create([
    'code' => 'GBP',
    'name' => 'British Pound',
    'exchange_rate' => 1.0000,
    'decimal_places' => 2,
    'enabled' => true,
    'default' => true,
]);
The default currency’s exchange rate is set to 1 as the base. To add EUR (Euros) when the exchange rate from GBP to EUR is 1.17, the value should be relative to the default: 1 / 1.17 = 0.8547. The exchange rate is independent of product pricing, as prices can be specified per currency directly. The exchange rate serves as a helper when working with prices.