---
title: "Reading & writing — Options for Laravel | Roundly"
description: "Get, set, check, forget and remember option values through the Options facade — globally or scoped to an owner."
url: https://roundly-consulting.com/open-source/docs/options-for-laravel/reading-writing
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Options for Laravel](https://roundly-consulting.com/open-source/docs/options-for-laravel.md)

# 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:

```php
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, caches “nothing stored” in both 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 and stores the result — but only if nothing is stored by then, so when two first callers race, both return the one value that was stored. Either way it returns the stored value, cast — the same type every later call returns. Handy for generated secrets:

```php
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:

```php
$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](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

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

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/options-for-laravel.md)
