laravel-site-settings maintained by karjah
Site Settings for Laravel
A lightweight, headless key-value settings engine with automatic caching.
Installation
- Install via composer:
composer require karjah/laravel-site-settings
- Run the migrations:
php artisan migrate
- Publish the config:
php artisan vendor:publish --tag=site-settings-config
Usage
Using the Model
You can interact with the settings directly via the Setting model. This is recommended for better IDE support.
use Karjah\SiteSettings\Models\Setting;
// Set a value
Setting::set('site_name', 'My Awesome Site');
// Get a value
$name = Setting::get('site_name', 'Default Name');
Using the Helper
For quick access in Blade views or controllers, you can use the global helper function:
// Set multiple values
site_setting([
'contact_email' => 'admin@example.com',
'maintenance_mode' => 'off'
]);
// Get a value
{{ site_setting('site_name') }}
Retrieving Values
The first call fetches from the database and caches the results forever; subsequent calls hit the cache for high performance.
Cache Management
The cache is automatically cleared whenever you use the set() method or the helper to update a value. If you manually edit the database directly, run:
php artisan cache:forget site_settings
Config
Ths published config file is just for a simple place to put settings to load with config('site-settings.')
You may need to refresh the config if the values have been cached:
php artisan config:clear