Skip to content

Commit b3a6d08

Browse files
committed
Add features doc to readme
1 parent 76b64ff commit b3a6d08

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,49 @@ Now you can access the results in `disabledOptions` or `hiddenOptions`
170170
})
171171
```
172172

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) {
206+
if($data['category']===-1){
207+
return $query->whereDoesntHave('categories');
208+
}
209+
210+
return $query->whereHas('categories', fn($query) => $query->whereIn('id', $categories));
211+
});
212+
})
213+
])
214+
```
215+
173216
## Filters
174217

175218
Use the tree in your table filters. Here's an example to show you how.

0 commit comments

Comments
 (0)