From db0642d594e3a70fb07a4c18be97408cf107e2ba Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Sun, 18 Dec 2022 18:08:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/HostController.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/HostController.php b/app/Http/Controllers/Admin/HostController.php index 4468359..458dd22 100644 --- a/app/Http/Controllers/Admin/HostController.php +++ b/app/Http/Controllers/Admin/HostController.php @@ -14,11 +14,22 @@ class HostController extends Controller * Display a listing of the resource. * * + * @param Request $request + * * @return View */ - public function index(): View + public function index(Request $request): View { - $hosts = Host::with('user')->paginate(100); + $hosts = Host::with('user'); + + // 遍历所有的搜索条件 + foreach (['name', 'module_id', 'status', 'user_id'] as $field) { + if ($request->has($field)) { + $hosts->where($field, 'like', '%' . $request->input($field) . '%'); + } + } + + $hosts = $hosts->paginate(100); return view('admin.hosts.index', compact('hosts')); }