Files
Xboard/app/Helpers/Functions.php
xboard a3c4cb1aea fix(setting): Resolve admin_setting helper incompatibility with Octane
Updated the `admin_setting` and `admin_settings_batch` helpers to retrieve the `Setting` instance from the service container. This fixes a fatal error and ensures correct behavior in a Laravel Octane environment by preventing the use of stale, shared static instances.
2025-07-04 22:16:19 +08:00

43 lines
1021 B
PHP

<?php
use App\Support\Setting;
use Illuminate\Support\Facades\App;
if (! function_exists('admin_setting')) {
/**
* 获取或保存配置参数.
*
* @param string|array $key
* @param mixed $default
* @return App\Support\Setting|mixed
*/
function admin_setting($key = null, $default = null)
{
$setting = app(Setting::class);
if ($key === null) {
return $setting->toArray();
}
if (is_array($key)) {
$setting->save($key);
return '';
}
$default = config('v2board.'. $key) ?? $default;
return $setting->get($key) ?? $default;
}
}
if (! function_exists('admin_settings_batch')) {
/**
* 批量获取配置参数,性能优化版本
*
* @param array $keys 配置键名数组
* @return array 返回键值对数组
*/
function admin_settings_batch(array $keys): array
{
return app(Setting::class)->getBatch($keys);
}
}