chapdel/model-settings-for-laravel
Attach flexible key/value settings to any Eloquent model in Laravel. Store, retrieve, and update per-model preferences with a simple API and database table, keeping configuration close to the data it belongs to. PHP 8+ compatible.
settings table (or customizable table name). Migration compatibility depends on the app’s existing schema. Potential conflicts if the app already uses a settings table with a different structure.Settings model by default. Apps with modular or namespaced settings (e.g., per-module configs) may need customization.key, value) could clash with existing apps. Customization may be needed.spatie/laravel-settings).config() + environment files, or packages like spatie/laravel-settings (more mature)?config/) be migrated to the database?settings table.// config/model-settings.php
'table' => 'app_settings',
'key_column' => 'config_key',
'value_column' => 'config_value',
config/ values to the database:
// Artisan command to seed initial settings
Settings::updateOrCreate(['key' => 'app_name'], ['value' => config('app.name')]);
config('key') calls with Settings::get('key') where dynamic updates are needed.config() cache to hybridize static/dynamic settings:
config(['app.name' => Settings::get('app_name')]);
config() caching or custom setting structures.config/ files for settings that are now database-backed.config() cache to avoid redundant DB calls.settings table may break the package.Settings::validate(['key' => 'theme_color'], ['value' => 'required|string|max:20']);
event(new SettingUpdated($setting));
$value = cache()->remember("setting_{$key}", now()->addHours(1), fn() => Settings::get($key));
DB::transaction(function () use ($key, $value) {
Settings::updateOrCreate(['key' => $key], ['value' => $value]);
});
settings table growth. Archive old settings if volume becomes an issue.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Database downtime | App crashes if settings are critical | Use fallback configs or caching. |
Corrupted settings table |
Invalid data breaks app | Regular backups; validate on read. |
| Concurrent write conflicts | Lost updates | Database transactions or optimistic locking. |
| Missing required setting | App throws exception | Default values or graceful degradation. |
| Schema migration errors | Integration fails | Test migrations in staging first. |
Settings::get(), Settings::set()).// Example: Import settings from JSON
php artisan settings:import path/to/settings.json
How can I help you explore Laravel packages today?