Laravel Scoped Settings is a lightweight Laravel package that provides a simple and elegant way to manage global and model-scoped application settings.
- ⚡ Supports global settings and per-model scoped settings
- 🎯 API via Facade and
setting()
helper - ✅ Includes artisan commands and full test suite
- 🚀 Optional per-scope caching built into
set()
andget()
You can install the package via Composer:
composer require danielemontecchi/laravel-scoped-settings
To customize default cache behavior, publish the config file:
php artisan vendor:publish --tag="laravel-scoped-settings-config"
To publish and run the migrations:
php artisan vendor:publish --tag="laravel-scoped-settings-migrations"
php artisan migrate
// Global settings
setting()->set('site.name', 'My App');
$siteName = setting()->get('site.name');
// Set with optional caching (global or scoped)
setting()->set('site.name', 'My App', 3600); // Cache for 1 hour
// If TTL is omitted, uses default from config (or disables cache)
setting()->set('site.name', 'My App'); // No cache if config is null
// Check if a setting exists (ignores fallback)
if (setting()->has('site.name')) {
// the value is explicitly set
}
// Scoped settings (e.g. per user)
setting()->for($user)->set('dashboard.layout', 'compact');
$layout = setting()->for($user)->get('dashboard.layout');
You can also retrieve all flat or grouped settings:
setting()->all(); // ['site.name' => 'My App']
setting()->for($user)->group('dashboard'); // ['layout' => 'compact']
Clear a specific key:
setting()->forget('site.name');
php artisan settings:list # Show all settings in CLI
php artisan settings:clear # Clear all settings
php artisan settings:export # Export settings to JSON
php artisan settings:import # Import settings from JSON
./vendor/bin/pest
Coverage reports are generated via phpunit.xml
config and uploaded to Codecov.
Full documentation available at:
👉 https://danielemontecchi.github.io/laravel-scoped-settings
Includes:
- Installation & Configuration
- Usage Examples
- Scoping Strategies
- Artisan Commands
- Advanced Tips
Laravel Scoped Settings is open-source software licensed under the MIT license. See the LICENSE.md file for full details.
Made with ❤️ by Daniele Montecchi