I need to find list of products which having category_id comes from checkbox input. this checkbox data comes as an array like 1,2 I used the following controller for finding the product . But problem is it only for first one. suppose for if there is only 1 in array it shows product having category 1 but if 1,2 is there in array it couldn't show the product which having category_id 1,2 only showing 1 category data.
public function searchByCheckbox(Request $request)
{
if(!empty($request->get('category_id')))
{
$category_id = implode(",",$request->get('category_id'));
$product = Product::where('category_id','=',$category_id)->get();
}
else
{
$product = Product::all();
}
return view('product', ['products' => $product]);
}
Aucun commentaire:
Enregistrer un commentaire