assign('upload_types', config('admin.upload_types')); $this->assign('editor_types', config('admin.editor_types')); } #[NodeAnnotation(title: '列表', auth: true)] public function index(Request $request): Json|string { return $this->fetch(); } #[NodeAnnotation(title: '保存', auth: true)] public function save(Request $request): void { $this->checkPostRequest(); $post = $request->post(); $notAddFields = ['_token', 'file', 'group']; try { $group = $post['group'] ?? ''; if (empty($group)) $this->error('保存失败'); if ($group == 'upload') { $upload_types = config('admin.upload_types'); // 兼容旧版本 self::$model::where('name', 'upload_allow_type')->update(['value' => implode(',', array_keys($upload_types))]); } foreach ($post as $key => $val) { if (in_array($key, $notAddFields)) continue; $config_key_data = self::$model::where('name', $key)->find(); if (!is_null($config_key_data)) { $config_key_data->save(['value' => $val,]); }else { self::$model::create( [ 'name' => $key, 'value' => $val, 'group' => $group, ]); } if (Cache::has($key)) Cache::set($key, $val); } TriggerService::updateMenu(); TriggerService::updateSysConfig(); }catch (\Exception $e) { $this->error('保存失败' . $e->getMessage()); } $this->success('保存成功'); } }