bonk007/system-settings
最新稳定版本:v1.1.0
Composer 安装命令:
composer require bonk007/system-settings
包简介
Dynamic settings for application
README 文档
README
Install
Install the package using composer
composer require bonk007/system-settings
then run migration
php artisan migrate
that's all ⚡
How to
Set setting's value
settings()->set('<group>.<key>', <value>);
example
settings()->set('global-settings.maintenance_scheduled_at', Carbon::parse('2024-07-01 00:00:00'));
if you need to set some value for specific configurable model (learn: what is configurable model)
settings()->for(<model instance>) ->set('<group>.<key>', <value>);
example
settings()->for(\App\Models\Organization::find(6)) ->set('invoice.number_format', 'INV/{SEQUENCE}/{MONTH}/{YEAR}');
or you can use
settings()->set('<group>.<key>.<table of configurable model>.<primary key>', <value>);
example
settings()->set('invoice.number_format.organizations.6', 'INV/{SEQUENCE}/{MONTH}/{YEAR}');
Get setting's value
settings('<group>.<key>', <default value>);
for specific configurable model
settings()->for(<configurable model>) ->get('<group>.<key>', <default value>);
or using simple way
settings('<group>.<key>.<table of configurable model>.<primary key>', <default value>)
example
settings('global-settings.maintenance_scheduled_at'); settings('invoice.number_format.organizations.6'); settings()->for(\App\Models\Organization::find(6)) ->get('invoice.number_format');
Remove setting
settings->unset('<group>.<key>')
with specific configurable model
settings->unset('<group>.<key>.<table of configurable model>.<primary key>')
or
settings()->for(<configurable model>) ->unset('<group>.<key>');
example
settings()->unset('global-settings.maintenance_scheduled_at'); settings()->unset('invoice.number_format.organizations.6'); settings()->for(\App\Models\Organization::find(6)) ->unset('invoice.number_format');
Configurable Model
Configurable model is a Eloquent Model represents an instance that owns custom configurations value.
How to define
Model should implement \Settings\Configurable::class interface
example
class User extends Model implements Configurable { // ... }
Be careful, using shortcut settings()->set('<group>.<key>.<table of configurable model>.<primary key>', <value>);, there is possibility you will store non-configurable model into settings table, then you can't use settings()->for(\App\Models\Organization::find(6)) for any function.
How it works
Configurable model will be stored as polymorphic relation at settings table. The field columns are configurable_table and configurable_id. By default configurable_id has unsigned bigint type, but you can change the type by define static variable \Settings\Manager::$configurableMorphType value with uuid|int|string at AppServiceProvider before you run artisan migrate.
class AppServiceProvider extends ServiceProvider
{
public function register()
{
// ...
\Settings\Manager::$configurableMorphType = 'uuid';
}
}
Accepted Value
stringbooleandouble/floatintegerarray\DatetimeInterface- Eloquent Model
- Model Collection
- Basic Collection
统计信息
- 总下载量: 63
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-14