Skip to content

Commit b9f6fed

Browse files
authored
Merge pull request #4 from 15web/fix-parent-select
Fix parent select's argument
2 parents 60c5113 + 8185788 commit b9f6fed

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Components/Form/ParentSelect.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Support\Str;
1010
use Kalnoy\Nestedset\NestedSet;
1111
use Kalnoy\Nestedset\QueryBuilder;
12+
use RuntimeException;
1213

1314
/**
1415
* Parent select builder
@@ -22,9 +23,14 @@ public static function make(QueryBuilder $query): Select
2223
$query->getModel()::class::getTreeLabelAttribute(),
2324
);
2425

26+
$depth = $item->getAttribute('depth');
27+
if ($depth < 1) {
28+
throw new RuntimeException('The tree is corrupted, please Fix tree');
29+
}
30+
2531
$prefix = Str::repeat(
2632
string: '--',
27-
times: $item->getAttribute('depth'),
33+
times: $depth,
2834
);
2935

3036
return trim("{$prefix} {$title}");

src/Components/Row.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Illuminate\Contracts\View\View;
1717
use Illuminate\Database\Eloquent\Model;
1818
use Kalnoy\Nestedset\NestedSet;
19+
use Kalnoy\Nestedset\QueryBuilder;
1920
use Livewire\Attributes\Computed;
2021
use Livewire\Attributes\On;
2122
use Livewire\Attributes\Session;
@@ -72,9 +73,11 @@ public function editAction(): EditAction
7273
$form = $this->component::getEditForm();
7374

7475
if (config('filament-tree.show-parent-select-while-edit')) {
76+
$model = $this->component::getModel();
77+
7578
array_unshift(
7679
$form,
77-
ParentSelect::make($this->component::getModel()),
80+
ParentSelect::make($model instanceof QueryBuilder ? $model : $model::query()),
7881
);
7982
}
8083

0 commit comments

Comments
 (0)