laravel-scoped-settings maintained by danielemontecchi
Description
Manage global and model-scoped settings in Laravel with a clean API, artisan commands, and optional per-scope caching.
Author
Last update
2026/03/27 16:54
(dev-main)
License
Downloads
9
Tags
Laravel Scoped Settings
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()
📦 Installation
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
🛠 Usage
// 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');
🛠 Artisan Commands
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
🧪 Testing
./vendor/bin/pest
Coverage reports are generated via phpunit.xml config and uploaded to Codecov.
📚 Documentation
Full documentation available at:
👉 https://danielemontecchi.github.io/laravel-scoped-settings
Includes:
- Installation & Configuration
- Usage Examples
- Scoping Strategies
- Artisan Commands
- Advanced Tips
License
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