Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Components/Form/ParentSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Support\Str;
use Kalnoy\Nestedset\NestedSet;
use Kalnoy\Nestedset\QueryBuilder;
use RuntimeException;

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

$depth = $item->getAttribute('depth');
if ($depth < 1) {
throw new RuntimeException('The tree is corrupted, please Fix tree');
}

$prefix = Str::repeat(
string: '--',
times: $item->getAttribute('depth'),
times: $depth,
);

return trim("{$prefix} {$title}");
Expand Down
5 changes: 4 additions & 1 deletion src/Components/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Kalnoy\Nestedset\NestedSet;
use Kalnoy\Nestedset\QueryBuilder;
use Livewire\Attributes\Computed;
use Livewire\Attributes\On;
use Livewire\Attributes\Session;
Expand Down Expand Up @@ -72,9 +73,11 @@ public function editAction(): EditAction
$form = $this->component::getEditForm();

if (config('filament-tree.show-parent-select-while-edit')) {
$model = $this->component::getModel();

array_unshift(
$form,
ParentSelect::make($this->component::getModel()),
ParentSelect::make($model instanceof QueryBuilder ? $model : $model::query()),
);
}

Expand Down