unisharp/laravel-settings
Laravel Settings gives your app persistent, database-backed configuration with a simple helper API. Store and retrieve key-value settings at runtime, cache them for performance, and avoid editing config files. Supports defaults, type casting, and quick setup for any Laravel project.
php artisan migrate. Check the README for the exact provider/tag used by your version:
composer require unisharp/laravel-settings
php artisan vendor:publish
php artisan migrate
config/settings.php for table name, cache behavior, and any package options.$title = settings('site.title', config('app.name'));
settings()->set('site.title', 'Acme');
// Some versions also support: settings(['site.title' => 'Acme']);
site.title, mail.from_address, billing.currency, features.checkout_v2. Keep a single source of truth for these keys, e.g. constants or a dedicated AppSettings class, so typos do not become silent fallback bugs.$currency = settings('billing.currency', 'USD');
This keeps fresh installs, failed migrations, and partially populated databases from breaking pages.public function update(SiteSettingsRequest $request)
{
DB::transaction(function () use ($request) {
foreach ($request->validated() as $key => $value) {
settings()->set($key, $value);
}
});
return back();
}
Wrap bulk updates in a transaction so a partial save does not leave mixed settings.class AppSettings
{
public static function bool(string $key, bool $default = false): bool
{
$value = settings($key, $default);
return filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? $default;
}
public static function array(string $key, array $default = []): array
{
$value = settings($key);
return $value === null ? $default : (json_decode($value, true) ?: $default);
}
}
.env/config; do not store API keys or passwords in a plain settings table unless you have encryption and access controls around it.{{ settings('site.title', config('app.name')) }}
Avoid calling settings repeatedly inside large loops; rely on the package cache but do not assume it is free.null, false, 0, and empty strings are meaningful:
if (settings()->has('features.checkout_v2')) {
// explicitly configured
}
$key = "tenant:{$tenant->id}:site.title";
RefreshDatabase, flush the cache in setUp, and set only the keys the test needs. Do not depend on settings persisted in your local development database.2.0.3 fixed a possible empty() bug. Pin at least that version, and still avoid relying on empty() semantics for settings. false, 0, and '' are valid values; use has()/strict null checks instead.php artisan cache:clear during debugging.settings() from config/*.php, package boot code, or anywhere that may run before the database is available. It will break config:cache, migrations, and early bootstrap paths. Prefer middleware, view composers, or service methods invoked after the app is fully booted.php artisan tinker:
settings()->all();
settings('site.title');
settings()->has('site.title');
Then inspect the settings table and the cache store. If a value “disappears,” check for null vs false/0, cache staleness, and whether the key was written under a different dotted namespace.AppSettings service, a settings schema config file with defaults and validation rules, an admin controller with audit logging, and a custom repository/model if you need tenant scoping or encrypted values. Keep those extensions in your app rather than modifying the vendor package unless you are prepared to maintain a fork.How can I help you explore Laravel packages today?