---
title: "Fluent API & bulk operations — Options for Laravel | Roundly"
description: "Chain calls on a single option, scope a batch to an owner with for(), and read or write many options in one go."
url: https://roundly-consulting.com/open-source/docs/options-for-laravel/fluent-api
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)

# Fluent API & bulk operations

Options::option() returns a context for a single global option; Options::for($owner) scopes everything that follows to an owner:

```php
Options::option(ThemeOption::class)->set('dark');
Options::option(ThemeOption::class)->get();       // or ->value()
Options::option(ThemeOption::class)->has();
Options::option(ThemeOption::class)->forget();    // or ->reset()
Options::option(ThemeOption::class)->default();
Options::option(ThemeOption::class)->remember(fn () => 'dark');
Options::option(ThemeOption::class)->key();       // 'theme'
Options::option(ThemeOption::class)->readable();  // 'Theme'

// Owner-scoped
Options::for($user)->option(ThemeOption::class)->set('light');
Options::for($user)->get(ThemeOption::class);
Options::for($user)->set(ThemeOption::class, 'light');
```

Options::for($owner) returns a PendingOptions builder with get(), set(), has(), forget(), reset(), remember(), many(), setMany() and all(), plus option() and key() to drop down to a single option. Options::for(null) is the global scope.

## Bulk reads and writes

```php
$values = Options::many([ThemeOption::class, LocaleOption::class]);
// [ThemeOption::class => 'dark', LocaleOption::class => 'en'] — keyed by what you passed

Options::setMany([ThemeOption::class => 'dark', LocaleOption::class => 'en']);

Options::for($user)->many(['theme', 'locale']);     // registered keys work too
Options::for($user)->setMany(['theme' => 'light']);

// Everything stored for a scope (raw key => value), in one query
$all = Options::all();               // global
$all = Options::for($user)->all();   // one owner
```

- many() returns an array keyed by the identifiers you passed — class-strings or registered keys.
- setMany() is all or nothing: every value is authorized and validated before the first write, and the writes share one database transaction. Casts, events and observers then apply as for set().
- all() is different: one query, raw stored strings keyed by option key. No casts, no defaults for unset options, and encrypted values stay ciphertext. With access control on, it leaves out what the current user may not read.

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