I need help to query a model base on its relationship:
I have a model called StoreStock
, this model is related to a Product
model, which has two model relationships, MasterList
and Price
.
I want to get all storeStock
with two Product relationships.
I know i can do something like
StoreStock::all()->with('product.price') ->get()
With this, i can only pick either price or masterlist
Advertisement
Answer
Pass array
of relationship to with
method
StoreStock::with(['product.price','product.masterlist']) ->get()