Global Helper Functions

Functions available everywhere: in controllers, Blade views and your plugin. Most live in app/Helpers/Helper.php; setting() comes with the settings store. The ones you will actually use are below; the rest of the file holds small legacy utilities.

Settings

FunctionBehaviour
setting(string $key, mixed $default = null): mixedRead a database setting. Settings are loaded once per request, so repeated calls are cheap
setting(array $values)Set several values (call setting()->save() afterwards)
setting()The settings store itself: ->set(), ->forget(), ->save()

On an installation that has not finished the installer the settings table may not exist yet; core code checks config('dotartisan.installed') before reading settings during boot. See Settings screens.

Theme options

FunctionBehaviour
theme_option(string $key, mixed $default = null): mixedValue for the active front theme: saved value, then the theme.json default, then $default
set_theme_option(string $key, mixed $value = null): voidOverride an option for the current request only; nothing is saved
override_theme_options(array|object $settings): voidApply many overrides at once, skipping empty values. Pages pass their settings JSON through it
theme_nested_option(string $key, ?string $default = null, string $theme = 'light'): ?stringRead a key inside a nested option array
google_fonts_list(int|false $index = false): arrayThe font catalogue used by font fields

Content and rendering

FunctionBehaviour
menu($idOrName, $type = null, array $options = []): mixedRender a menu (by id or name) with one of the theme's templates in menu/: bootstrap, megamenu, mobile, footer, topbar, list, inline. '_json' returns the item tree instead of HTML. The tree is cached for 15 minutes and cleared when the menu changes
menuIcon(MenuItem $item): mixedThe HTML for a menu item's icon (inline SVG, image or icon class)
clean_page_builder(mixed $html): mixedStrip the <body> wrapper from page-builder output before saving
sanitize_html(mixed $html): mixedstrip_tags() keeping only strong, a, p, div, span. It does not remove attributes, so it is not an XSS filter for untrusted input
record_page_visit($model): boolCount a view of a model that tracks views, with the cooldown from the cooldown_expires_hours setting
getPageType(Page $page)The AppPages definition a page serves (AppPages::firstForPage())
bsColumns(int $columns = 3)Bootstrap row-columns classes for a responsive grid (row-cols-md-3 row-cols-sm-2 row-cols-1)
pluginView($view, $params)Render alias::view, preferring a copy in views/plugins/{alias}/ when one exists
setActive(string $path): stringReturns ' active' when the current path starts with $path

Files

FunctionBehaviour
fileUpload(UploadedFile $input, ?string $path = null): string|falseStore an upload on the public files disk (PUBLIC_FILES_DISK) under $path (default {month}/{day}) and return its URL. It keeps the client's original file name, so a second upload with the same name replaces the first: validate type and size, and prefer the media library for anything user-facing
tempFileUpload(UploadedFile $input, bool $public = false, bool $onlyUrl = false, ?string $dir = null)Store in the temporary area with a generated name; returns details (disk, path, url, size…) or just the URL. php artisan dotartisan:clean-temp removes old files
generateFileUrl($path, $disk)Storage::disk($disk)->url($path)
sanitize_filename($name, bool $allow_extension = true): string, slugify_name($name, bool $timestamp = true)Safe file names

Text, numbers and lists

FunctionBehaviour
__e(?string $key, array $params = []): stringTranslate, or return an empty string when the key is empty
format_number(int $number): stringShort form: 1200 → 1.2K, 3 000 000 → 3M
get_initials(string $name): stringUp to two initials (Ada Lovelace → A L)
available_currencies(): arrayISO 4217 code → currency name
timezones_list(): arrayTimezone choices for selects
job_cache_time($hours = null)A timestamp $hours ahead (default config('dotartisan.cache_time'))

Module helpers

Modules can ship their own global functions through autoload.files in their composer.json. TruCommerce does (Modules/TruCommerce/trucommerce.php), for example trucommerce_money($amount, $currency) for formatted prices and trucommerce_order_statuses(). Prefix your own functions with your alias and wrap each in if (! function_exists(...)).

Helpers from frameworks you will see