修复 N + 1 的问题
This commit is contained in:
parent
c77ca46395
commit
79dd6cdf8d
@ -20,7 +20,7 @@ class HostController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(Request $request): View
|
public function index(Request $request): View
|
||||||
{
|
{
|
||||||
$hosts = Host::with('user');
|
$hosts = new Host();
|
||||||
|
|
||||||
// 遍历所有的搜索条件
|
// 遍历所有的搜索条件
|
||||||
foreach (['name', 'module_id', 'status', 'user_id', 'price', 'managed_price', 'created_at', 'updated_at'] as $field) {
|
foreach (['name', 'module_id', 'status', 'user_id', 'price', 'managed_price', 'created_at', 'updated_at'] as $field) {
|
||||||
@ -29,6 +29,8 @@ public function index(Request $request): View
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hosts = $hosts->with(['user', 'module']);
|
||||||
|
|
||||||
$hosts = $hosts->paginate(50)->withQueryString();
|
$hosts = $hosts->paginate(50)->withQueryString();
|
||||||
|
|
||||||
return view('admin.hosts.index', compact('hosts'));
|
return view('admin.hosts.index', compact('hosts'));
|
||||||
|
Loading…
Reference in New Issue
Block a user