Can anyone help, I'm out of ideas.
I have this code:
$item = ItemsBrandOitb::select('ItmsGrpCod')->where('Brand', '=', $brand)->first();
return ItemsOitm::where('Country', $country)
->where('OnHand', '>', 0)
->where('ItmsGrpCod','=', $item->ItmsGrpCod)
->with([
'price' => function($q) use ($country){
return $q->where('Country', $country);
},
'stock'=> function($q) use ($country){
return $q->where('Country', $country);
},
'brand' => function($q) use ($brand){
return $q->whereHas('Brand', '=', $brand);
}
]
)->groupBy('U_GeralRef')->orderBy('ColectionDate', 'desc')->get();
Does anyone know how to put this query:
$item = ItemsBrandOitb::select('ItmsGrpCod')->where('Brand', '=', $brand)->first();
//here:
->where('ItmsGrpCod','=', $item->ItmsGrpCod)
So I can have only one database query?
Thanks