NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Options for Laravel

Reading & writing

The Options facade (backed by OptionsManager) is the main entry point. Every method takes an option class-string or a registered key, plus an optional owner model:

use RoundlyConsulting\Options\Facades\Options;

Options::resolve(ThemeOption::class);             // OptionInterface
Options::get(ThemeOption::class);                 // current value (or the default)
Options::set(ThemeOption::class, 'dark');         // persist a value
Options::get(ThemeOption::class, $user);          // scoped read
Options::set(ThemeOption::class, 'light', $user); // scoped write
Options::has(ThemeOption::class);                 // is a value stored?
Options::forget(ThemeOption::class);              // delete (revert to default)
Options::reset(ThemeOption::class);               // alias of forget()
  • get() returns the stored value cast through castAs(), or default() when nothing is stored for that scope — always the cast type, also right after set().
  • set() checks access, validates against rules(), serializes the value through its cast, upserts the scope’s row, caches the raw stored value and fires OptionSet with the cast value.
  • has() is true only when a row exists — a stored value that equals the default still counts.
  • forget() soft-deletes the row, clears both cache layers and fires OptionForgotten; reset() is an alias.
  • resolve() returns the option instance bound to the owner.

Remember

remember() returns the stored value when there is one; otherwise it calls the closure, stores the result and returns what was stored, cast — the same type every later call returns. Handy for generated secrets:

use Illuminate\Support\Str;
use RoundlyConsulting\Options\Facades\Options;

// Stored value if there is one; otherwise store the closure result and return it.
$secret = Options::remember(WebhookSecretOption::class, fn () => Str::random(40));

// Scoped to an owner:
$secret = Options::remember(WebhookSecretOption::class, fn () => Str::random(40), $team);

No global fallback

Scopes are independent. When nothing is stored for an owner, get() returns the option’s default() — not the global value. If owners should inherit an app-wide value, check the owner scope first:

$theme = Options::has(ThemeOption::class, $user)
    ? Options::get(ThemeOption::class, $user)
    : Options::get(ThemeOption::class);       // fall back to the global value

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 crypto

By 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.