Search by

roundly-consulting / options-for-laravel

mihaliak

Manage global or per-entity options and preferences with typed casts and in-request caching.

Package info

github.com/roundly-consulting/options-for-laravel

pkg:composer/roundly-consulting/options-for-laravel

Fund package maintenance!

Patreon

Statistics

Installs: 16

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-10-03 17:56 UTC

This package is auto-updated.

Last update: 2026-10-03 18:05:54 UTC


README

Options for Laravel — Roundly open source

Latest release Tests Code style Donate Patreon Crypto

Options for Laravel

Global or per-model options, settings and preferences for Laravel. Each option is a small class with its key, default value, cast and validation rules; values can belong to the whole app or to any Eloquent model (a user, a team, a tenant) and are cached, typed and evented.

Installation

Requires PHP 8.4 and Laravel 12 or 13.

composer require roundly-consulting/options-for-laravel
php artisan vendor:publish --tag="options-migrations"
php artisan migrate

If your owner models have UUID/ULID keys, set OPTIONS_KEY_TYPE before migrating.

Usage

Describe an option once (php artisan make:option ThemeOption --key=theme scaffolds it):

use RoundlyConsulting\Options\BaseOption;

final class ThemeOption extends BaseOption
{
    public function key(): string
    {
        return 'theme';
    }

    public function default(): mixed
    {
        return 'light';
    }

    public function rules(): array|string
    {
        return ['in:light,dark'];
    }
}

Then read and write it — globally or for any model:

use RoundlyConsulting\Options\Facades\Options;

Options::get(ThemeOption::class);                 // 'light' — the default until a value is stored
Options::set(ThemeOption::class, 'dark');         // validated against rules(), cached, fires OptionSet

Options::set(ThemeOption::class, 'light', $user); // scoped to one model
Options::for($user)->get(ThemeOption::class);     // 'light'
Options::forget(ThemeOption::class, $user);       // back to the default

Documentation

The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/options-for-laravel

Release notes are in CHANGELOG.md. To contribute, see the contributing guide.

Support our work

This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.

Donate to Roundly open source Become a patron on Patreon Donate crypto: BTC, ETH, BNB or SOL

License

The MIT License (MIT). See LICENSE for details.