jomigomes/laravel-settings
Composer 安装命令:
composer require jomigomes/laravel-settings
包简介
A flexible Laravel package for managing scoped, typed settings with a manifesto-based configuration approach
README 文档
README
A flexible Laravel package for managing scoped, typed settings with a manifesto-based configuration approach.
Features
- Scoped Settings: Associate settings with specific models or application segments
- Type Safety: Automatic type casting and validation for various data types
- Manifesto-Based: Single source of truth for settings structure and defaults
- Default Values: Settings are stored in config until changed, preventing database clutter
- Flexible Organization: Support for nested groups and dot notation access
- Model Integration: Easy integration with Eloquent models via the
HasSettingstrait - Events System: Listen to setting lifecycle events (retrieved, created, updated, deleted)
- Facade Support: Clean API with
Settingsfacade - CLI Commands: Manage settings via artisan commands
- Optional Caching: Performance optimization with configurable cache layer
Supported Types
- Integer
- Double
- Boolean
- String
- Array
- Collection (Illuminate\Support\Collection)
- Datetime (Carbon instances)
- Object
Installation
Install the package via Composer:
composer require jomigomes/laravel-settings
Publish the configuration file:
php artisan vendor:publish --tag=settings-config
Publish and run the migration:
php artisan vendor:publish --tag=settings-migrations php artisan migrate
Configuration
The package uses a "manifesto" file (config/settings.php) as the single source of truth for all settings. Define your settings structure here:
use JomiGomes\LaravelSettings\Models\Setting; return [ 'system' => [ 'features' => [ 'enable_notifications' => [ 'value' => true, 'type' => Setting::TYPE_BOOLEAN, ], ], ], 'user' => [ 'preferences' => [ 'theme' => [ 'value' => 'light', 'type' => Setting::TYPE_STRING, ], ], ], ];
Usage
Non-Model Related Settings
use JomiGomes\LaravelSettings\Facades\Settings; // Or use the model directly: // use JomiGomes\LaravelSettings\Models\Setting; // Get a setting $setting = Settings::get('features.enable_notifications', 'system'); // Set a setting Settings::set('features.enable_notifications', false, 'system'); // Get all settings for a scope $allSettings = Settings::getAllScoped('system'); // Get filtered settings $features = Settings::getFiltered('system', 'features');
Model Related Settings
First, add the HasSettings trait to your model:
use JomiGomes\LaravelSettings\Traits\HasSettings; class User extends Model { use HasSettings; }
Then use settings with your model:
$user = User::find(1); // Get a setting $theme = $user->getSetting('preferences.theme'); // Set a setting $user->setSetting('preferences.theme', 'dark'); // Get all settings $allSettings = $user->getAllSettings(); // Get filtered settings $preferences = $user->getFilteredSettings('preferences');
Events
Listen to setting changes in your EventServiceProvider:
use JomiGomes\LaravelSettings\Events\SettingUpdated; protected $listen = [ SettingUpdated::class => [ LogSettingChange::class, ], ];
Available events:
SettingRetrieved- Fired when a setting is accessedSettingCreated- Fired when a new setting is storedSettingUpdated- Fired when an existing setting changesSettingDeleted- Fired when a setting reverts to default
Artisan Commands
# List all settings php artisan settings:list # List settings for a specific scope php artisan settings:list user # List with filter php artisan settings:list user --filter=preferences # Show only customized settings php artisan settings:list user --only-custom # Clear all customized settings php artisan settings:clear --force # Clear settings for a scope php artisan settings:clear user # Clear with filter php artisan settings:clear user --filter=preferences
Caching
Enable caching for improved performance in your .env:
SETTINGS_CACHE_ENABLED=true SETTINGS_CACHE_TTL=3600
Or in config/settings.php:
'cache' => [ 'enabled' => true, 'ttl' => 3600, // seconds ],
Documentation
For complete documentation, see the Settings.md file included in this package.
Testing
composer test
License
This package is open-sourced software licensed under the MIT license.
Credits
Created by João Gomes
jomigomes/laravel-settings 适用场景与选型建议
jomigomes/laravel-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「configuration」 「laravel」 「Settings」 「typed-settings」 「scoped-settings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jomigomes/laravel-settings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jomigomes/laravel-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jomigomes/laravel-settings 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Persistent settings package for Laravel framework.
Configuration component
A Zend Framework module to quickly and easily set PHP settings.
Settings Card for Laravel Nova.
Utils to load, parse and work with configuration on Mezzio projects
Extends basic Wordpress features.
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-08