modified setting
This commit is contained in:
parent
ecb09c87cb
commit
860f718459
|
|
@ -19,6 +19,32 @@ function setting($key, $default = null)
|
||||||
return config("bk.{$key}", $default);
|
return config("bk.{$key}", $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统 settings
|
||||||
|
*
|
||||||
|
* @param $group
|
||||||
|
* @param $key
|
||||||
|
* @param null $default
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function system_setting($group, $key, $default = null)
|
||||||
|
{
|
||||||
|
return config("bk.{$group}.{$key}", $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取后台设置到 settings 表的值
|
||||||
|
*
|
||||||
|
* @param $plugin
|
||||||
|
* @param $key
|
||||||
|
* @param null $default
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function plugin_setting($plugin, $key, $default = null)
|
||||||
|
{
|
||||||
|
return config("bk.{$plugin}.{$key}", $default);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取后台管理前缀名称, 默认为 admin
|
* 获取后台管理前缀名称, 默认为 admin
|
||||||
*/
|
*/
|
||||||
|
|
@ -37,22 +63,7 @@ function admin_name(): string
|
||||||
*/
|
*/
|
||||||
function load_settings()
|
function load_settings()
|
||||||
{
|
{
|
||||||
$settings = Setting::all(['type', 'space', 'name', 'value', 'json'])
|
$result = \Beike\Repositories\SettingRepo::getGroupedSettings();
|
||||||
->groupBy('space');
|
|
||||||
|
|
||||||
$result = [];
|
|
||||||
foreach ($settings as $space => $groupSettings) {
|
|
||||||
$space = $space ?: 'system';
|
|
||||||
foreach ($groupSettings as $groupSetting) {
|
|
||||||
$name = $groupSetting->name;
|
|
||||||
$value = $groupSetting->value;
|
|
||||||
if ($groupSetting->json) {
|
|
||||||
$result[$space][$name] = json_decode($value, true);
|
|
||||||
} else {
|
|
||||||
$result[$space][$name] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
config(['bk' => $result]);
|
config(['bk' => $result]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ class Setting extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
const TYPES = ['system', 'plugin'];
|
||||||
|
|
||||||
protected $table = 'settings';
|
protected $table = 'settings';
|
||||||
protected $fillable = ['type', 'space', 'name', 'value', 'json'];
|
protected $fillable = ['type', 'space', 'name', 'value', 'json'];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,32 @@ use Beike\Models\Setting;
|
||||||
|
|
||||||
class SettingRepo
|
class SettingRepo
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 按照类型分组获取设置
|
||||||
|
*/
|
||||||
|
public static function getGroupedSettings(): array
|
||||||
|
{
|
||||||
|
$settings = Setting::all(['type', 'space', 'name', 'value', 'json']);
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
foreach ($settings as $setting) {
|
||||||
|
$type = $setting->type;
|
||||||
|
if (!in_array($type, Setting::TYPES)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$space = $setting->space;
|
||||||
|
$name = $setting->name;
|
||||||
|
$value = $setting->value;
|
||||||
|
if ($setting->json) {
|
||||||
|
$result[$type][$space][$name] = json_decode($value, true);
|
||||||
|
} else {
|
||||||
|
$result[$type][$space][$name] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取插件默认字段
|
* 获取插件默认字段
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue