laravel-settings maintained by centrex
Manage settings in Laravel
Database-backed application settings with a caching layer, Laravel config integration, and convenient helper functions. Settings are stored in a settings table and cached forever until changed.
Installation
composer require centrex/laravel-settings
php artisan vendor:publish --tag="laravel-settings-migrations"
php artisan migrate
Usage
Via helper functions
// Get a setting (with optional default)
settings('site.name', 'My App');
get_setting('site.name', 'My App');
// Set a setting
set_setting('site.name', 'Acme Corp');
// Check existence
setting_exists('site.name'); // true
// Remove a setting
remove_setting('site.name');
// Get the Settings service instance
$settingsService = settings();
Via facade
use Centrex\Settings\Facades\Settings;
Settings::set('maintenance.enabled', true);
Settings::get('maintenance.enabled', false);
Settings::has('maintenance.enabled');
Settings::forget('maintenance.enabled');
// Force a cache refresh
Settings::refreshCache();
Config integration
Settings are merged into the Laravel config on boot via chargeConfig(). After that, database settings are accessible through config():
config('site.name'); // returns the value stored in the settings table
Caching
- Reads use
Cache::rememberForeverper key. - Any
set()orforget()call automatically flushes the cache and reloads config.
Testing
composer test # full suite
composer test:unit # pest only
composer test:types # phpstan
composer lint # pint
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.