Simply use Orwhere and joined as like below.
$item = ItemsBrandOitb::select('ItmsGrpCod')->where('Brand', '=', $brand)->Orwhere('ItmsGrpCod','=', $item->ItmsGrpCod)->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello
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();
Dos 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
Please or to participate in this conversation.