我正在开发一个项目,在那里我使用了预先加载,我希望减少SQL查询
ScreenShot1
ScreenShot2
public function showAllOrdersbySite($domain_id){
$orders = Order::whereHas('paymentStatus', function ($query) use($domain_id) {
$query->where("domain_id","=",$domain_id);
})->orderby('tbl_orders.created_at', 'desc')->paginate(20);
return View('admin.all_orders')
->with('orders',$orders);
}
答案 0 :(得分:0)
http://forumsarchive.laravel.io/viewtopic.php?id=5104
https://laracasts.com/forum/?p=95-best-practice-to-minimize-db-queries/0
laravel eager loading to minimize queries
此链接可能会有所帮助......
答案 1 :(得分:0)
我不知道要添加功能,我只是通过添加这样的方法来解决我的问题 来源:Eager Load Constraints Filter issue in Laravel
public function showAllOrdersbySite($domain_id){
$orders = Order::with('func1',func2)->whereHas('paymentStatus', function ($query) use($domain_id) {
$query->where("domain_id","=",$domain_id);
})->orderby('tbl_orders.created_at', 'desc')->paginate(20);
return View('admin.all_orders')
->with('orders',$orders);
}
答案 2 :(得分:0)
使用Laravel Eager加载或Laravel LAzy Eager Loading。 Laravel LAzy渴望加载满足您的要求