Skip to content

Commit ec13e35

Browse files
committed
- remove default sort from toHierarchy()
- reimplement as to toSortedHierarchy()
1 parent 1113583 commit ec13e35

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Baum/Extensions/Eloquent/Collection.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ class Collection extends BaseCollection {
77

88
public function toHierarchy() {
99
$dict = $this->getDictionary();
10-
11-
// Enforce sorting by $orderColumn setting in Baum\Node instance
12-
uasort($dict, function($a, $b){
13-
return ($a->getOrder() >= $b->getOrder()) ? 1 : -1;
14-
});
15-
1610
return new BaseCollection($this->hierarchical($dict));
1711
}
1812

13+
public function toSortedHierarchy() {
14+
$dict = $this->getDictionary();
15+
16+
// Enforce sorting by $orderColumn setting in Baum\Node instance
17+
uasort($dict, function($a, $b){
18+
return ($a->getOrder() >= $b->getOrder()) ? 1 : -1;
19+
});
20+
21+
return new BaseCollection($this->hierarchical($dict));
22+
}
23+
1924
protected function hierarchical($result) {
2025
foreach($result as $key => $node)
2126
$node->setRelation('children', new BaseCollection);

0 commit comments

Comments
 (0)