Laravel 查询&数据库&模型

1.with()与load区别:

都称为 延迟预加载,不同点在于 load()是在已经查询出来的模型上调用,而 with() 则是在 ORM 查询构造器上调用。

Order::query()->with(['items.product','items.productSku'])->paginate();

    public function show(Order $order, Request $request)
    {
        return view('orders.show', ['order' => $order->load(['items.productSku', 'items.product'])]);
    }

  

猜你喜欢

转载自www.cnblogs.com/bing2017/p/10888115.html
今日推荐