-
-
Save fayzasalman/0f32faa7ebc257c05cedc44c33726025 to your computer and use it in GitHub Desktop.
Revisions
-
etrepat renamed this gist
Oct 10, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
etrepat revised this gist
Oct 10, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ foreach($root->children as $category) { } ``` This approach is ok if you don't need to go too deep under your hierarchy tree (usually 1 to 3 levels). If you'd need to traverse your tree deeper or, maybe get the full hierarchy tree, you could consider a simple recursive approach. ```PHP <?php -
etrepat revised this gist
Oct 10, 2013 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,8 @@ foreach($root->children as $category) { This approach is ok if you don't need to go too deep under your hierarchy tree (usually 1 to 3 levels). If you'd need to traverse your tree deeper or, maybe get the full hierarchy tree, a recursive approach should be better. ```PHP <?php $roots = Category::roots()->get(); echo "<ul>"; -
etrepat revised this gist
Oct 10, 2013 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ The simplest way to traverse the hierarchy tree with [Baum](https://github.com/etrepat/Baum) is by iterating through the `children` relation. ```PHP <?php $root = Category::roots()->with('children')->first(); echo "<h3>{$root->name}</h3>"; -
etrepat renamed this gist
Oct 10, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ foreach($root->children as $category) { This approach is ok if you don't need to go too deep under your hierarchy tree (usually 1 to 3 levels). If you'd need to traverse your tree deeper or, maybe get the full hierarchy tree, a recursive approach should be better. ```PHP $roots = Category::roots()->get(); echo "<ul>"; -
etrepat revised this gist
Oct 10, 2013 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ The simplest way to traverse the hierarchy tree with [Baum](https://github.com/etrepat/Baum) is by iterating through the `children` relation. ```PHP $root = Category::roots()->with('children')->first(); echo "<h3>{$root->name}</h3>"; -
etrepat created this gist
Oct 10, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ The simplest way to traverse the hierarchy tree with [Baum](https://github.com/etrepat/Baum) is by iterating through the `children` relation. ```php $root = Category::roots()->with('children')->first(); echo "<h3>{$root->name}</h3>"; foreach($root->children as $category) { echo "<li>"; echo "<b>{$category->name}</b>"; if ( $category->children()->count() > 0 ) { echo "<ul>"; foreach($category->children as $subCategory) echo "<li>{$subCategory}</li>"; echo "</ul>"; } echo "</li>"; } ``` This approach is ok if you don't need to go too deep under your hierarchy tree (usually 1 to 3 levels). If you'd need to traverse your tree deeper or, maybe get the full hierarchy tree, a recursive approach should be better. ```php $roots = Category::roots()->get(); echo "<ul>"; foreach($roots as $root) renderNode($root); echo "</ul>"; // *Very simple* recursive rendering function function renderNode($node) { echo "<li>"; echo "<b>{$node->name}</b>"; if ( $node->children()->count() > 0 ) { echo "<ul>"; foreach($node->children as $child) renderNode($child); echo "</ul>"; } echo "</li>"; } ```