where('key', $key)->value('value'); } catch (Throwable) { return $default; } if ($setting === null) { return $default; } $decoded = json_decode($setting, true); return json_last_error() === JSON_ERROR_NONE ? $decoded : $setting; } public static function setValue(string $key, mixed $value): void { if (! static::settingsTableExists()) { return; } $storedValue = is_string($value) ? $value : json_encode($value); static::query()->updateOrCreate( ['key' => $key], ['value' => $storedValue] ); } public static function bool(string $key, bool $default = false): bool { return filter_var(static::getValue($key, $default), FILTER_VALIDATE_BOOL); } protected static function settingsTableExists(): bool { try { $model = new static(); return $model->getConnection()->getSchemaBuilder()->hasTable($model->getTable()); } catch (Throwable) { return false; } } }