hankz/laravel-system-settings
Composer 安装命令:
composer require hankz/laravel-system-settings
包简介
A Laravel package designed for managing system configuration values in database.
README 文档
README
English Document | 繁體中文文件
Laravel System Settings
A Laravel package designed for managing system configuration values in database.
Installation
1. Composer install
Run the Composer require command from the Terminal:
composer require hankz/laravel-system-settings
2. Setup
This package supports Laravel's auto-discovery feature and it's ready to use once installed.
3. Publishing the config file
You need publish the config file.
php artisan vendor:publish --provider="Hankz\LaravelSystemSettings\SystemSettingProvider"
4. Configuration
You can configure this package in config\system-settings.php
<?php return [ /** * use table name. */ 'table_name' => 'system_settings', /** * default value. */ 'default' => [ 'group' => 'default', ], ];
- table_name - Save the system settings table name in the database.
- default.group - The default group name when you are missing the group parameter.
5. Migration
You should also run the migrate command.
php artisan migrate
Usage
This package is very simple and provides the following methods for your use.
new(string $key, string $value, string $group = null, string $description = null): bool
Create a new system setting.
Parameters:
$key(string): The unique identifier for the system setting.$value(string): The value associated with the system setting.$group(string|null): (Optional) The group to which the system setting belongs. Default isnull.$description(string|null): (Optional) A description providing additional information about the system setting. Default isnull.
Example:
SystemSettingManager::new('keyName', 'value', 'groupName', 'description');
Returns:
bool: Returnstrueif the system setting is created successfully, or throws aSystemSettingAlreadyExistsExceptionif the setting already exists.
has(string $key, string $group = null): bool
The has() method checks if a system setting exists with the given key and optional group.
Parameters:
$key(string): The unique identifier for the system setting.$group(string|null): (Optional) The group to which the system setting belongs. Default isnull.
Example:
SystemSettingManager::has('keyName', 'groupName');
Returns:
bool: Returnstrueif the system setting exists, otherwisefalse.
all(): array
Return all system settings with key and value in the format of key-value pairs.
Example:
SystemSettingManager::all();
Returns:
array: An associative array containing all system settings in the format['key' => 'value'].
get(string $key, string $group = null, string $default = null): null|string
The get() method allows you to retrieve the value using both the key name and group name, and it also accepts a default value.
Parameters:
$key(string): The unique identifier for the system setting.$group(string|null): (Optional) The group to which the system setting belongs. Default isnull.$default(string|null): (Optional) The default value to return if the system setting is not found. Default isnull.
Example:
SystemSettingManager::get('keyName', 'groupName', 'defaultValue');
Returns:
string|null: Returns the value of the system setting if found, otherwise returns the specified default value ornullif no default is provided.
set(string $key, string $value, string $group = null, string $description = null, bool $createWhenNotExist = false): void
The set() method allows you to update the value and description of an existing system setting or create a new one if it does not exist.
Parameters:
$key(string): The unique identifier for the system setting.$value(string): The new value to set for the system setting.$group(string|null): (Optional) The group to which the system setting belongs. Default isnull.$description(string|null): (Optional) A description providing additional information about the system setting. Default isnull.$createWhenNotExist(bool): (Optional) If set totrue, a new system setting will be created if the specified key does not exist. Default isfalse.
Example:
SystemSettingManager::set('keyName', 'newValue', 'groupName', 'newDescription', true);
Returns:
void
getByGroup(string $group): array
Retrieve all system settings within a specified group.
Parameters:
$group(string): The group from which to retrieve system settings.
Example:
SystemSettingManager::getByGroup('groupName');
Returns:
array: An associative array containing system settings within the specified group in the format['key' => 'value'].
setByGroup(array $settings, string $group = null, bool $createWhenNotExist = false): void
Update or create multiple system settings within a specified group.
Parameters:
$settings(array): An associative array containing system settings in the format['key' => ['value' => '', 'description' => '']].$group(string|null): (Optional) The group to which the system settings belong. Default isnull.$createWhenNotExist(bool): (Optional) If set totrue, new system settings will be created for keys that do not exist in the specified group. Default isfalse.
Example:
SystemSettingManager::setByGroup(['key1' => ['value' => 'value1', 'description' => 'desc1']], 'groupName', true);
Returns:
void
delete(string $key, string $group = null): bool|null
Delete a system setting with the specified key and optional group.
Parameters:
$key(string): The unique identifier for the system setting.$group(string|null): (Optional) The group to which the system setting belongs. Default isnull.
Example:
SystemSettingManager::delete('keyName', 'groupName');
Returns:
bool|null: Returnstrueif the system setting is successfully deleted,falseif the setting does not exist, ornullif an error occurs.
To-do list
- Add audit log
License
MIT License © 2023 Hankz
hankz/laravel-system-settings 适用场景与选型建议
hankz/laravel-system-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「configuration」 「laravel」 「Settings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hankz/laravel-system-settings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hankz/laravel-system-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hankz/laravel-system-settings 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Configuration component
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
Utils to load, parse and work with configuration on Mezzio projects
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-11