Receiving the request in array format
[
[
[
'condition1',
'value1',
],
[
'condition2',
'value2',
],
],
[
'condition3',
'value4',
]
]
Im trying to build query builder with values1 and values 2 in 'or' condition and value3 in 'and' condition
$result = DB::table('table ')
foreach($values as $value){ //
$result->where(function ($qry) use ($value) { // array 0,1 with and condition
foreach($value as $val){ // values1 , values2
$qry->where();
}
});
}
How to add 'or' condition between the values1 and values2 and then 'and' condition with value3.
Don't need any loop, you need sub query, like this :
$result = DB::table('table')
->where(function($query) use($value1) {
$query->where('condition1', $value1)
->orWhere('condition2', $value1);
})
->where('condition3', $value2)
->get();