Skip to content

Commit b6c7b11

Browse files
Update README.md
1 parent a04d3c2 commit b6c7b11

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

README.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ composer require codewithdennis/filament-select-tree
2020
php artisan filament:assets
2121
```
2222

23-
## Features
24-
25-
- Dark Mode: It seamlessly supports both Filament's light and dark modes out of the box.
26-
- Search: Searching is fully supported, and it seamlessly searches through all levels within the tree structure.
27-
- BelongsTo Integration: Establish connections within your data effortlessly.
28-
- BelongsToMany Integration: Simplify the management of complex relationships through BelongsToMany integration.
29-
3023
## Usage
3124

3225
Import the `SelectTree` class from the `CodeWithDennis\FilamentSelectTree` namespace
@@ -53,6 +46,38 @@ SelectTree::make('category_id')
5346
})
5447
```
5548

49+
Use the tree in your table filters. Here's an example to show you how.
50+
51+
52+
```bash
53+
use Filament\Tables\Filters\Filter;
54+
use Illuminate\Database\Eloquent\Builder;
55+
```
56+
57+
```php
58+
->filters([
59+
Filter::make('tree')
60+
->form([
61+
SelectTree::make('categories')
62+
->relationship('categories', 'name', 'parent_id')
63+
->independent(false)
64+
->enableBranchNode(),
65+
])
66+
->query(function (Builder $query, array $data) {
67+
return $query->when($data['categories'], function ($query, $categories) {
68+
return $query->whereHas('categories', fn($query) => $query->whereIn('id', $categories));
69+
});
70+
})
71+
->indicateUsing(function (array $data): ?string {
72+
if (! $data['categories']) {
73+
return null;
74+
}
75+
76+
return __('Categories') . ': ' . implode(', ', Category::whereIn('id', $data['categories'])->get()->pluck('name')->toArray());
77+
})
78+
])
79+
```
80+
5681
Set a custom placeholder when no items are selected
5782

5883
```PHP

0 commit comments

Comments
 (0)