laravel 预加载特定的列
/**订单列表 0 已删除 1执行中 2 已过期
*
* @param Request $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @author lxw
*/
public function getOrderList( Request $request )
{
$this->closeSqlFullMode();
$query = $this->buildingPayment->query();
$status = $request['status'] ?? '1';
switch( $status ) {
case '1': //执行中
$query->whereDate('duetime', '>', date('Y-m-d', time()));
break;
case '2': //已到期
$query->whereDate('duetime', '<=', date('Y-m-d', time()));
break;
case '0': //已删除
$query->onlyTrashed();
break;
default:
$query->whereDate('duetime', '>', date('Y-m-d', time()));
}
// $orderLists = $query->groupBy('order_id')->orderBy('created_at', 'desc')->paginate(env('PAGE_LIMIT'));
//优化后
$orderLists = $query->groupBy('order_id')->with(['companies:id,username','manages:id,username','buildings:id,name'])->orderBy('created_at', 'desc')->paginate(env('PAGE_LIMIT'));
return view('Manage.Payment.PaymentList', ['orderLists' => $orderLists, 'links' => ['status' => $status]]);
}
赞赏码
![](https://files.cnblogs.com/files/lxwphp/zhifubao2.bmp)
![](https://files.cnblogs.com/files/lxwphp/weixin.bmp)
非学,无以致疑;非问,无以广识