I need to get all products for category and sub categories when click on parent category
so i make loop or recursive loop to get all id for category and subcategory to search for its products
public function tree($category, $cats = array())
{
$items = category_model::select('id')-where('parent_id', $category)-get();
foreach ($items as $key=$value)
{
//$cats = $value;
$cats = Arr::add($cats, 'id', $value);
self::tree($value, $cats);
}
return $cats;
}
public function allproduct(Request $request)
{
return self::tree($request-id);
}
I have tried this code but looping with our result
I need to add this all id to make search for products through this array
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire