Skip to content

Commit 350a313

Browse files
committed
Allow 'parentId' is null or negative integer
1 parent ede4319 commit 350a313

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Support/Utils.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,22 @@ public static function buildNestedArray(
4949
{
5050
$branch = [];
5151
$parentId = is_numeric($parentId) ? intval($parentId) : $parentId;
52-
if (blank($parentId)) {
53-
$parentId = self::defaultParentId();
54-
}
52+
// if (blank($parentId)) {
53+
// $parentId = self::defaultParentId();
54+
// }
5555
$primaryKeyName = $primaryKeyName ?: 'id';
5656
$parentKeyName = $parentKeyName ?: static::parentColumnName();
5757
$childrenKeyName = $childrenKeyName ?: static::defaultChildrenKeyName();
5858

5959
$nodeGroups = collect($nodes)->groupBy(fn ($node) => $node[$parentKeyName])->sortKeys();
6060
foreach ($nodeGroups as $pk => $nodeGroup) {
6161
$pk = is_numeric($pk) ? intval($pk) : $pk;
62-
if ($pk === $parentId) {
62+
if (
63+
($pk === $parentId)
64+
// Allow parentId is nullable or negative number
65+
// https://github.com/solutionforest/filament-tree/issues/28
66+
|| (($pk === '' || $pk <= 0) && $parentId <= 0)
67+
) {
6368
foreach ($nodeGroup as $node) {
6469
$node = collect($node)->toArray();
6570

0 commit comments

Comments
 (0)