Level 60
$query->with(['batches.stock'])
->select(['name'])
->orderBy('name', 'asc')
->limit(1);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
$query->with(['batches'])->select(['name'])->orderBy('name', 'asc')->limit(1);
Result:
"batches": [
{
"id": 3079,
"cost": 100,
"stock": 20
},
{
"id": 3080,
"cost": 100,
"stock": 20
}
]
I am getting the batches for the relationship with Products Model. But from batches I want to get all stock. How will I write my query?
Please or to participate in this conversation.