### Install Options for Laravel with Composer and publish migrations Source: https://github.com/roundly-consulting/options-for-laravel/blob/main/README.md Run these commands to install the package, publish its migrations, and run the migrations. Requires PHP 8.4 and Laravel 12 or 13. Set OPTIONS_KEY_TYPE before migrating if your owner models use UUID/ULID keys. ```bash composer require roundly-consulting/options-for-laravel php artisan vendor:publish --tag="options-migrations" php artisan migrate ``` -------------------------------- ### Define a ThemeOption class extending BaseOption Source: https://github.com/roundly-consulting/options-for-laravel/blob/main/README.md Example of an option class that defines key, default value, and validation rules. Scaffold with `php artisan make:option ThemeOption --key=theme`. The default is 'light' and rules require 'light' or 'dark'. ```php 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 ['required', 'in:light,dark']; } } ``` -------------------------------- ### Read and write options globally or per model using Options facade Source: https://github.com/roundly-consulting/options-for-laravel/blob/main/README.md Shows how to get, set, and forget option values globally or scoped to a model. Values are validated, cached, and fire the OptionSet event. The comment shows the default 'light' is returned until a value is stored. ```php 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 ```