has('theme_key') && !empty($request->theme_key)) { $query->where('theme_key', $request->theme_key); } $list = $query->orderBy('bid', 'desc')->paginate(20); // 获取所有主题用于筛选 $themes = WebThemeConfig::all(); return view('admin.banner.index', [ 'list' => $list, 'theme_key' => $request->theme_key ?? '', 'themes' => $themes ]); } public function add(Request $request) { if ($request->isMethod('post')) { $validator = Validator::make($request->all(), [ 'img' => 'required|string', 'alt' => 'nullable|string', 'link_game' => 'nullable|integer', 'link_module' => 'nullable|integer', 'theme_key' => 'nullable|string|max:30', ]); if ($validator->fails()) { return apiReturnFail($validator->errors()->first()); } $data = $request->only(['img', 'img_pt', 'img_es', 'alt', 'link_game', 'link_module', 'theme_key']); Banner::create($data); return apiReturnSuc(); } $themes = WebThemeConfig::all(); return view('admin.banner.add', ['themes' => $themes]); } public function edit(Request $request, $id) { $info = Banner::findOrFail($id); if ($request->isMethod('post')) { $validator = Validator::make($request->all(), [ 'img' => 'required|string', 'alt' => 'nullable|string', 'link_game' => 'nullable|integer', 'link_module' => 'nullable|integer', 'theme_key' => 'nullable|string|max:30', ]); if ($validator->fails()) { return apiReturnFail($validator->errors()->first()); } $data = $request->only(['img', 'img_pt', 'img_es', 'alt', 'link_game', 'link_module', 'theme_key']); $info->update($data); return apiReturnSuc(); } $themes = WebThemeConfig::all(); return view('admin.banner.edit', [ 'info' => $info, 'themes' => $themes ]); } public function delete($id) { $info = Banner::findOrFail($id); $info->delete(); return apiReturnSuc(); } }