Helpers, registry & Blade
Two global helpers cover the common cases. Both are function_exists-guarded, so your app can define its own instead:
options(); // OptionsManager instance
options(ThemeOption::class); // global value
options(ThemeOption::class, $user); // scoped value
options()->set(ThemeOption::class, 'dark');
setting('theme'); // identical alias
setting('theme', $user);String-key registry
Register short keys so options resolve by string — useful in Blade, config-driven UIs and the CLI. Register them in a service provider:
use RoundlyConsulting\Options\Facades\Options;
// In a service provider’s boot()
Options::register([
'theme' => ThemeOption::class,
'locale' => LocaleOption::class,
]);
Options::key('theme')->get();
options('theme', $user);
Options::for($user)->key('theme')->set('dark');
Options::registered(); // ['theme' => ThemeOption::class, …]
Options::resolveClass('theme'); // ThemeOption::classOr declare them in config:
// config/options.php
'registry' => [
'theme' => App\Options\ThemeOption::class,
'locale' => App\Options\LocaleOption::class,
],- Runtime registrations win over config entries with the same key.
- A registry key is only a lookup alias — the value is still stored under the option’s key().
- Dotted keys such as profile.theme are a naming convention; they aren’t stored as groups.
- Registry keys and class-strings funnel through one resolver; an unknown key or class throws InvalidOptionClassName.
Blade directive
{{-- registered key or class-string; output is HTML-escaped --}}
@option('theme')
@option(\App\Options\ThemeOption::class)
{{-- the arguments are passed straight to options(), so an owner works too --}}
@option('theme', auth()->user())@option compiles to options(...) wrapped in e(), so output is HTML-escaped and access control applies. If your app already defines an @option directive, the package leaves yours in place and skips its own.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.