Typed runtime settings in Laravel Rust
Choose the smallest supported settings group
Replace one database-backed group of non-secret runtime settings, such as a display title and a registration-enabled flag. Keep deployment configuration in environment/config files. Do not recreate reflection-based discovery, arbitrary casts, Redis repositories, settings migrations, or encrypted-secret storage. It is not a tested drop-in port; verify it with the trial checklist below.
Check get-recipe's current port catalog for community Rust ports and alternatives, inspect compatibility and maintenance, and offer a compatible port before choosing app-owned logic. A catalog listing is not an audit.
Read the reference contract
At the baseline in Sources, settings classes declare a group and typed properties. SettingsMapper loads declared names, applies casts/decryption, fills missing values from declared defaults, and rejects other missing properties. A default permits reading but does not mean a settings migration has created the persisted property: saving can still fail. Database storage encodes each property's payload separately as JSON, uniquely identified by (group, name).
Saving filters out locked properties, writes the remaining values, and reloads locked values. A locked flag is an administrative write prohibition, not a database concurrency lock. Settings instances and optional serialized caches have their own lifetimes. An app-owned Rust struct is not automatically refreshed just because a database row changed.
Application-owned read and write paths
- Inventory actual settings classes, names, defaults, casts, repository overrides, encryption declarations, events, cache prefixes, and CLI writers. If the selected group contains encrypted or custom-cast values, keep those properties on the old implementation until an independently reviewed conversion exists. Do not deserialize PHP serialized objects in Rust.
- Reuse the existing table through the app's model/query layer. Hardcode the selected group and allowlist of property names; neither SQL identifiers nor group identity come from request input. Preserve raw JSON representation and existing values. Do not add a migration or rewrite unrelated groups just to follow the recipe.
- Decode the two selected values into a typed Rust snapshot. Distinguish missing rows, JSON null, invalid types, and valid
false/empty strings. Defaults must be explicit product decisions, notunwrap_or_default()masking corrupt data. Use the installedserde_jsonAPIs and the target app's actual database JSON representation; avoid encoding a JSON string twice. - Authenticate and authorize the settings-write operation server-side. Validate the complete patch before starting writes. Use the application's transaction callback and lock the required existing rows in a stable order on its production driver. Read current
lockedflags inside that transaction. A cached snapshot must never grant write permission. The pinned Laravel Rust database transaction callback scopes same-connection queries automatically; don't spawn tasks that escape it. - Update only explicitly supplied, unlocked names. For stale-edit protection, compare the caller's expected snapshot with current values after locking, or use an existing version mechanism. Return a conflict instead of losing another administrator's edit. Required rows must already exist; locking a nonexistent row is not an initialization strategy. All writers must follow the same protocol; SQLite needs its own compatible write-serialization tests.
- Start without a cross-request settings cache unless the app needs it. Read once per operation and pass an immutable snapshot. If caching is retained, invalidate/update only the selected group after commit, with tenant identity where applicable. Never reuse a mutable global settings object across users. An after-commit cache error does not undo a committed database write; report and recover without telling the caller the transaction rolled back.
Compatibility and security boundaries
This subset has no implicit multi-tenancy. If settings are tenant-specific, scope storage, authorization, cache keys, worker context, and concurrency together; a prefix in a cache key alone does not isolate database rows. Do not expose a whole settings object as a public JSON response. Keep secrets out of logs, error payloads, and source-controlled defaults. Laravel PHP encryption payloads and Rust encryption APIs are not assumed interoperable.
Trial checklist
- Read existing Unicode strings and both boolean values correctly; distinguish missing, null, corrupt JSON, and wrong JSON type.
- Deny an unauthorized write without changing data or caches. An attempted locked-property edit must preserve the persisted value under the declared error/ignore policy.
- Two independent connections edit different fields, then the same field using stale snapshots. Verify preserved unrelated changes and the documented conflict result.
- Inject failure after the first field write: neither field commits and no success/cache event is emitted.
- A warm cache, a second request, and a long-lived worker observe the committed update without leaking another tenant's values. An unrelated cache sentinel survives invalidation.
- Compare source-backed defaults and locked-field behavior before removing the package for this group. Existing encrypted groups remain readable by their original owner.
Run cargo fmt --all --check, strict Clippy, and the actual app's settings integration tests using its production database driver. Record versions, driver, concurrency results, and deliberate differences with the change.
Sources
- MIT reference: spatie/laravel-settings 3.10.3. Read
src/Settings.php,SettingsMapper.php,SettingsConfig.php,SettingsRepositories/DatabaseSettingsRepository.php,SettingsEventSubscriber.php,SettingsCache.php,tests/SettingsTest.php, and the table migration stub. PreserveLICENSE.mdwhen adapting source. - Framework baseline: Laravel Rust 0.1.3, source. Check the app's lockfile before using database/transaction APIs.
- Port context: check
get-recipe's current port catalog (sourced from Package Port) at implementation time.