Closed dijkr closed 1 year ago
Eventually its done with: $products = Product::where('category', $category)->get(); $groupedProducts = $products->groupBy('Subcategory'); The parents (keys) of its parent-array is called the value of the subcategory. So the indexed numbers are replaced by that.
This will create a collection with arrays. Every array contains arrays where every array is a row where the pluck value is equal. So basically nesting arrays.
This then could loop over each subcategory that contain products with the same subcategory. Once finished, it should loop over the next subcategory.