get(); return view('admin.game-configs.index', compact('games')); } /** * 切换游戏开启/关闭状态。 */ public function toggle(GameConfig $gameConfig): JsonResponse { $gameConfig->update(['enabled' => ! $gameConfig->enabled]); $gameConfig->clearCache(); return response()->json([ 'ok' => true, 'enabled' => $gameConfig->enabled, 'message' => $gameConfig->enabled ? "「{$gameConfig->name}」已开启" : "「{$gameConfig->name}」已关闭", ]); } /** * 保存游戏核心参数。 * * 接收前端提交的 params JSON 对象并合并至现有配置。 */ public function updateParams(Request $request, GameConfig $gameConfig): RedirectResponse { $request->validate([ 'params' => 'required|array', ]); // 合并参数,保留已有键,只更新传入的键 $current = $gameConfig->params ?? []; $updated = array_merge($current, $request->input('params')); $gameConfig->update(['params' => $updated]); $gameConfig->clearCache(); return back()->with('success', "「{$gameConfig->name}」参数已保存!"); } }