Skip to content

Commit 7841cfb

Browse files
committed
feat: add pivot data
1 parent 611a43a commit 7841cfb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/SelectTree.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Filament\Forms\Components\Concerns\CanBeSearchable;
1111
use Filament\Forms\Components\Concerns\HasActions;
1212
use Filament\Forms\Components\Concerns\HasAffixes;
13+
use Filament\Forms\Components\Concerns\HasPivotData;
1314
use Filament\Forms\Components\Concerns\HasPlaceholder;
1415
use Filament\Forms\Components\Contracts\HasAffixActions;
1516
use Filament\Forms\Components\Field;
@@ -26,6 +27,7 @@ class SelectTree extends Field implements HasAffixActions
2627
use HasActions;
2728
use HasAffixes;
2829
use HasPlaceholder;
30+
use HasPivotData;
2931

3032
protected string $view = 'select-tree::select-tree';
3133

@@ -103,6 +105,12 @@ protected function setUp(): void
103105
// Wrap the state in a collection and convert it to an array if it's not set.
104106
$state = Collection::wrap($state ?? []);
105107

108+
if($pivotData = $component->getPivotData()) {
109+
$component->getRelationship()->syncWithPivotValues($state->toArray(), $pivotData);
110+
111+
return;
112+
}
113+
106114
// Sync the relationship with the provided state (IDs).
107115
$component->getRelationship()->sync($state->toArray());
108116
}

0 commit comments

Comments
 (0)