Skip to content
Advertisement

Query More than one relationship from a model with() in Laravel

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() 
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement