I need to build a query in Laravel 6 that has nested where's in one where query. for example: Select * FROM example where k=5 and ((i=1 and j=2) or (i=3 and j=4) or (i=5 and j=4)......)
i tried the code below
$getItems = $getItems->where(function ($query) use($codes,$cID) {
$query->orWhere(function ($query1) use ($codes, $cID) {
foreach($codes[$cID] as $code) {
$query1
->where('code', $code)
->where('cid', $cID);
}
});
});
but the result is wrong.
and (("code" = ? and "cid" = ?)) and (("code" = ? and "cid" = ?)) and (("code" = ? and "cid" = ?))....
I don't understand why it adds 2 parenthesis in every foreach loop and why it adds "and" instead of "or". Any suggestions on how to build this?