php - How to eagerly load multiple related models in Laravel 5? -
i have relationships follows:
an order
has many product
s, , product
has many order
s.
class order extends model { ... public function products() { return $this->belongstomany('app\product'); } }
a product
has many image
s, , image
belongs product
.
class product extends model { ... public function images() { return $this->hasmany('app\image'); } }
for order $order
, can load products $order->load('products')
, how eagerly load images
of products $order
?
there 2 ways achieve this, can $order->load('products.images')
or add property $with = ['images']
product
model/entity.
Comments
Post a Comment