validate($request, [ 'filter' => [ 'nullable', 'string', 'min:1', 'max:20', Rule::in(['autocw', 'unlisted', 'banned']) ], ]); if($request->has('filter') && $request->filled('filter')) { switch ($request->filter) { case 'autocw': $instances = Instance::whereAutoCw(true)->orderByDesc('id')->paginate(5); break; case 'unlisted': $instances = Instance::whereUnlisted(true)->orderByDesc('id')->paginate(5); break; case 'banned': $instances = Instance::whereBanned(true)->orderByDesc('id')->paginate(5); break; } } else { $instances = Instance::orderByDesc('id')->paginate(5); } return view('admin.instances.home', compact('instances')); } public function instanceScan(Request $request) { DB::transaction(function() { Profile::select('domain')->whereNotNull('domain') ->groupBy('id') ->groupBy('domain') ->chunk(50, function($domains) { foreach($domains as $domain) { Instance::firstOrCreate([ 'domain' => $domain->domain ]); } }); }); return redirect()->back(); } public function instanceShow(Request $request, $id) { $instance = Instance::findOrFail($id); return view('admin.instances.show', compact('instance')); } public function instanceEdit(Request $request, $id) { $this->validate($request, [ 'action' => [ 'required', 'string', 'min:1', 'max:20', Rule::in(['autocw', 'unlist', 'ban']) ], ]); $instance = Instance::findOrFail($id); $unlisted = $instance->unlisted; $autocw = $instance->auto_cw; $banned = $instance->banned; switch ($request->action) { case 'autocw': $instance->auto_cw = $autocw == true ? false : true; $instance->save(); break; case 'unlist': $instance->unlisted = $unlisted == true ? false : true; $instance->save(); break; case 'ban': $instance->banned = $banned == true ? false : true; $instance->save(); break; } return response()->json([]); } }