Open source
Options for Laravel
composer require roundly-consulting/options-for-laravelOverview
A native settings layer for Laravel. Each option is a small class that declares its key, default and cast — and, when you need them, encryption, validation and access rules. Values live in one options table, either global or scoped to any Eloquent model: a user, a team, a tenant. Reads are memoised for the current request or queued job and optionally cached across requests, writes keep both layers in step and fire events, and a config bridge lets stored values override config() at boot. MIT-licensed and built on Laravel alone, plus Roundly’s own package toolkit.
What you get
Global or per-owner
One options table for app-wide values and values scoped to any Eloquent model — users, teams, tenants.
Typed casts & encryption
Any Laravel cast, a custom CastsAttributes, a backed-enum cast, and at-rest encryption per option.
Two-layer caching
A per-request memo plus an optional persistent cache that flushes on any store. Both hold the raw stored value, and writes keep them in step.
Settings-screen groups
Bundle options into groups whose definition() hands your UI labels, help text, sections, order, types and current values.
Opt-in access control
Per-option read/write hooks, optional Gate abilities, actingAs() and withoutAuthorization() — off until you enable it.
Config bridge, events & CLI
Stored options override config() without a redeploy. OptionSet and OptionForgotten events, targeted observers and eight Artisan commands.
Facade, DI or actions
Use the Options facade, inject OptionsManager or call the export and import actions — Options::fake() records every write, whichever path made it.
Documentation
Installation
Install via Composer, publish and run the options table migration, and optionally publish the config to edit the registry or swap the model.
Configuration
Every config key and its default — model, owner key type, registry, cache, events, groups, authorization and the config bridge.
Database schema & key type
The single options table, how key_type types the owner columns for bigint, UUID or ULID owners, and swapping in your own model.
Defining options
Extend BaseOption to declare an option’s key, default, cast, encryption, rules and presentation — or scaffold one with make:option.
The Options facade
The full Options facade surface — flat verbs, for(), option(), key() and group() handles, registry, observers, access control and cache.
DI and actions
Skip the facade: inject OptionsManager for the same API without static calls, or call the export and import actions directly.
Reading & writing
Get, set, check, forget and remember option values through the Options facade — globally or scoped to an owner.
Fluent API & bulk operations
Chain calls on a single option, scope a batch to an owner with for(), and read or write many options in one go.
Owners & the HasOptions trait
Scope values to any Eloquent model — users, teams, tenants — and read them straight off the model with the HasOptions trait.
Helpers, registry & Blade
The options() and setting() helpers, short string keys through the registry, and the escaped @option Blade directive.
Casts & encryption
Cast values with any Laravel cast, a custom CastsAttributes or the backed-enum cast, and encrypt sensitive options at rest.
Validation
Return Laravel validation rules from rules() and every write is validated before it’s cast or stored.
Events
OptionSet, OptionForgotten and the opt-in OptionResolved — what each carries, when it fires and how to switch them off.
Observers
React to one specific option changing — closures or invokable classes, fired on set and forget in registration order.
Setting groups
Bundle related options into a group that reads, writes and describes a whole settings screen in one call.
Access control
Opt-in per-option read and write rules, Gate abilities, acting as a user, bypassing for system jobs and CLI authorization.
Config bridge
Let stored options override Laravel config() values at boot — change mail senders or the app name from the database.
Caching
The per-request memo and the persistent cache — what they hold, how writes keep them fresh, and how a flush works on any store.
Import & export
Move options between environments or seed defaults with Options::export(), exportJson() and import() — or the matching Artisan commands.
Artisan commands
Eight commands to scaffold options and groups, list, get and set values, clear caches, and export or import settings.
Testing
Options::fake() records every write in memory with six assertions; or test against the real table with factory states.
Exceptions
Every package exception, when it’s thrown, and the framework exceptions you may also meet.
Requirements
PHP 8.4+, Laravel 12 or 13, and Roundly’s package toolkit, which Composer installs for you.
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.