I send an array with ajax included category_id as shown in image. And catch these categories in controller to execute product row equal with category_id field in products table. In this case, i cannot loop the array as category_id sending from ajax for where condition in controller. Pls guide me…….
public function productCategoryList(Request $request)
{
logger($request->status);
$data = Products::where('category_id', $request->status)->get();
return $data;
}
2
Answers
You could use
whereIn()
on your query builder:That would allow you to query a list of elements, instead of a single element.
The documentation for how to use
whereIn()
can be found at https://laravel.com/docs/10.x/queries#additional-where-clausesYou can use
whereIn()
that allows you to filter query results based on a given array of values.