I'm using Laravel and I try to use pagination for my products
array:4 [▼
0 => Product {#770 ▶}
1 => Product {#766 ▶}
2 => Product {#814 ▶}
3 => Product {#846 ▶}
]
And I get these from a method like this
$this->getAllCategoriesProducts(31)
31 is ID of category
and this is my method :
public function getAllCategoriesProducts($cat_id){
$allProducts = [];
foreach(ProductCategory::find($cat_id)->children()->get() as $subCategory){
if($subCategory->children()->exists()){
foreach($subCategory->children()->get() as $subSubCategory){
foreach($subSubCategory->products()->get() as $product){
$allProducts[] = $product;
}
}
if($subSubCategory->children()->exists()){
foreach($subSubCategory->children()->get() as $subSubSubCategory){
foreach($subSubSubCategory->products()->get() as $product){
$allProducts[] = $product;
}
if($subSubSubCategory->children()->exists()){
foreach($subSubSubCategory->children()->get() as $subSubSubSubCategory){
foreach($subSubSubSubCategory->products()->get() as $product){
$allProducts[] = $product;
}
}
}
}
}
}
}
return $allProducts;
}
but when I use
$this->getAllCategoriesProducts($categroyId)->paginate(8)
it gives me this error
Call to a member function paginate() on array