增加 条件搜索
This commit is contained in:
parent
c404b41a43
commit
db0642d594
@ -14,11 +14,22 @@ class HostController extends Controller
|
|||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
* @return View
|
* @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'));
|
return view('admin.hosts.index', compact('hosts'));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user