Use a whereIn
return $query->whereIn('ProductGroup', $searchData['product_group']);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
So i have this form where a user can search for product data and can filter it by ProductGroup.
The user has to be able to select more than one ProductGroup. How would i be able to add this to query?
Example
The data passed through from the form is this
$searchData = [
'product_group' =>[
0=>'test1',
1=>'test2',
2=>'test3'
]
];
I have a query at the moment which check that the passed through values have values before adding them to the query.
My query at the moment is
$results = StockProfitReportView::
when(count($searchData['product_group']) > 0, function($query) use($searchData) {
return $query->where('ProductGroup', $searchData['product_group']);
})->get();
So how can i do it so it add a 'OR' line for every product group so the final query will look a little bit like
$results = StockProfitReportView::
->where('ProductGroup', 'test1')
->orWhere('ProductGroup', 'test2')
->orWhere('ProductGroup', 'test3')
->get();
If i have not explained this very well please let me know and i will try to clear it up.
Thank you in advance
Use a whereIn
return $query->whereIn('ProductGroup', $searchData['product_group']);
Please or to participate in this conversation.