You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -170,6 +170,49 @@ Now you can access the results in `disabledOptions` or `hiddenOptions`
170
170
})
171
171
```
172
172
173
+
By default, multiple or single selection in the tree is determined by the type of the relationship. Single for `BelongsTo` multiple for `BelongsToMany`. If you want explicitly set the type of selection use:
174
+
175
+
```PHP
176
+
->multiple(false) //or true, Closure that returns boolean
177
+
```
178
+
179
+
If you need to prepend an item to the tree menu use `prepend`. Method accept an array or closure. Useful when tree-select is used as a filter (see example below).
180
+
181
+
```php
182
+
use Filament\Tables\Filters\Filter;
183
+
use Illuminate\Database\Eloquent\Builder;
184
+
use CodeWithDennis\FilamentSelectTree\SelectTree;
185
+
```
186
+
187
+
```php
188
+
->filters([
189
+
Filter::make('tree')
190
+
->form([
191
+
SelectTree::make('category')
192
+
->relationship('categories', 'name', 'parent_id')
193
+
->multiple(false)
194
+
->prepend([
195
+
'name'=>'Uncategorized Products', //required
196
+
'value'=>-1, //required
197
+
'parent' => null // optional
198
+
'disabled' => false // optional
199
+
'hidden' => false // optional
200
+
'children'=>[] //optional
201
+
])
202
+
])
203
+
->query(function (Builder $query, array $data) {
204
+
$categories= [(int) $data['category']];
205
+
return $query->when($data['category'], function ($query, $categories) {
0 commit comments