| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Http\Controllers\Admin;
- use App\Game\Banner;
- use App\Game\WebThemeConfig;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Validator;
- class BannerController
- {
- public function index(Request $request)
- {
- $query = Banner::query();
- // 可以根据主题筛选
- if ($request->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();
- }
- }
|