$settings */ public static function setSettings(array $settings): void { foreach ($settings as $key => $value) { static::writeOption($key, $value); } } /** * Read one option. Keys that were never stored read as null. */ public static function getSetting(string $key): mixed { return static::query() ->where('option', $key) ->value('value'); } /** * Read several options at once, as an option => value map. * * Keys without a row are left out of the map entirely: callers get a * shorter map, never a null placeholder. * * @param array $settings * @return Collection */ public static function getSettings(array $settings): Collection { return static::query() ->whereIn('option', $settings) ->pluck('value', 'option'); } /** * The shared write rule behind both public writers: update in place when * the option is already known, insert it otherwise. */ private static function writeOption(string $key, mixed $value): void { static::query()->updateOrCreate(['option' => $key], ['value' => $value]); } }