danielemontecchi/laravel-scoped-settings
最新稳定版本:v1.2.0
Composer 安装命令:
composer require danielemontecchi/laravel-scoped-settings
包简介
Manage global and model-scoped settings in Laravel with a clean API, artisan commands, and optional per-scope caching.
README 文档
README
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
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-16