Helpers

Global helper functions and model methods you'll use most when building on WemX.

Global helpers

Defined in app/helpers.php and available everywhere.

settings()

Read or write application settings (the settings table, cached).

settings('app_name');                       // read
settings('suspend_period', 3);              // read with default
settings(['example_api_url' => $url]);      // write one or more keys
settings('example_encrypted_token');        // keys containing "encrypted" are decrypted on read

price() / priceIn()

Format money, converting from the base currency to the visitor's active currency.

price(19.99);                                       // "€18.40" if the visitor picked EUR
price(19.99, to: 'USD');                            // force a currency
price($amount, in: 'EUR', to: 'USD', absolute: true); // converted float, no formatting
priceIn(10, 'GBP');                                 // format an amount that is already in GBP

Currency

baseCurrency();     // the store's base currency, e.g. "USD"
activeCurrency();   // the visitor's selected display currency

Views and assets

client_view('tickets::tickets.index', $data);   // theme-aware view resolution
admin_view('tickets::tickets.index', $data);
client_asset('css/app.css');                    // /assets/clientarea/{theme}/css/app.css?v=…
admin_asset('js/app.js');

Other helpers

HelperReturns
extensionElements('navigation-item')Registered elements of one or more types
extensions()The Extension model, e.g. extensions()->findById('tickets')
cart()The current visitor's cart
daysToPeriod(30)A translated cycle label, e.g. "Monthly"
utils()Misc utilities, e.g. utils()->checkStatus() for scheduler health

Facades

ClassPurpose
App\Facades\TaxTax::calculateSalesTax($amount, $country, $state, $taxId, $gatewayConfigId) returns the amount before and after tax, the tax amount, rate and name
App\Facades\Worldcountries(), states($country), countryName($code), languages(), timezones(), currencies()
App\Facades\ModelSettingsPer-model key/value settings, used through the HasSettings trait

Useful model methods

Order

$order->option('memory');            // config option value, falling back to the package setting
$order->price;                       // cycle total
$order->daily_price;                 // daily rate including options
$order->isActive(); $order->isRecurring(); $order->cycle();
$order->createServer(); $order->suspendServer(); $order->unsuspendServer(); $order->terminateServer();
$order->getExternalUser(); $order->createExternalUser([...]); $order->hasExternalUser();
$order->log(['action' => '…', 'description' => '…']);

User

$user->hasPermission('admin.orders.view');
$user->isStaff(); $user->isAdmin();
$user->updateBalance('+', 10.00, 'Promotional credit');   // '+', '-' or '='
$user->email(['subject' => '…', 'lines' => ['…']]);
$user->activeBan();

Payment

$payment->total(); $payment->isPaid();
$payment->completed($transactionId, $providerData);
$payment->data('cart_id');
$payment->successUrl(); $payment->cancelUrl(); $payment->webhookUrl(); $payment->callbackUrl();

Package

$package->data('egg_id');                                  // package server setting
$package->isVisibleToUser($user);
$package->configurableOptionCalculator($options, 30);      // price breakdown for options
Package::query()->visibleToUser($user)->get();

On this page