vanilophp / category

Category Module for Vanilo (or any Laravel app) https://vanilo.io
MIT License
7 stars 4 forks source link

Getting all nested childrens (recursive) #2

Closed frantisek-heca closed 4 years ago

frantisek-heca commented 4 years ago

Please, I haven't tried this package, but I am mostly interested if children method will return all nested categories, preferably in a tree view (nested array)?

If not, how would you get it? For building menus.

fulopattila122 commented 4 years ago

I would start from the root level taxons and then iterate through the children:

foreach ($taxonomy->rootLevelTaxons() as $root) {
    foreach ($root->children() as $child) {
        $child->children();//...and so on
    }
}