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
+72-24
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,8 @@
3
3
[](https://packagist.org/packages/codewithdennis/filament-select-tree)
This package adds a dynamic select tree field to your Laravel / Filament application, allowing you to create interactive hierarchical selection dropdowns based on relationships. It's handy for building selection dropdowns with various customization options.
6
+
This package adds a dynamic select tree field to your Laravel / Filament application, allowing you to create interactive hierarchical selection dropdowns based on relationships. It's handy for
7
+
building selection dropdowns with various customization options.
By default, the type of selection in the tree (single or multiple) is determined by the relationship type: `BelongsTo` for single selection and `BelongsToMany` for multiple selection. If you want to
175
+
explicitly set the selection type, use:
176
+
177
+
```php
178
+
->multiple(false)
179
+
```
180
+
181
+
If you need to prepend an item to the tree menu, use the `prepend` method. This method accepts an array or a closure. It is useful when the tree-select is used as a filter (see example below).
182
+
183
+
```php
184
+
use Filament\Tables\Filters\Filter;
185
+
use Illuminate\Database\Eloquent\Builder;
186
+
use CodeWithDennis\FilamentSelectTree\SelectTree;
187
+
```
188
+
189
+
```php
190
+
->filters([
191
+
Filter::make('tree')
192
+
->form([
193
+
SelectTree::make('category')
194
+
->relationship('categories', 'name', 'parent_id')
195
+
->enableBranchNode()
196
+
->multiple(false)
197
+
->prepend([
198
+
'name' => 'Uncategorized Records',
199
+
'value' => -1,
200
+
'parent' => null, // optional
201
+
'disabled' => false, // optional
202
+
'hidden' => false, // optional
203
+
'children' => [], // optional
204
+
])
205
+
])
206
+
->query(function (Builder $query, array $data) {
207
+
$categories = [(int) $data['category']];
208
+
209
+
return $query->when($data['category'], function (Builder $query, $categories) {
0 commit comments