@@ -20,13 +20,6 @@ composer require codewithdennis/filament-select-tree
20
20
php artisan filament:assets
21
21
```
22
22
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
-
30
23
## Usage
31
24
32
25
Import the ` SelectTree ` class from the ` CodeWithDennis\FilamentSelectTree ` namespace
@@ -53,6 +46,38 @@ SelectTree::make('category_id')
53
46
})
54
47
```
55
48
49
+ Use the tree in your table filters. Here's an example to show you how.
50
+
51
+
52
+ ``` bash
53
+ use Filament\T ables\F ilters\F ilter;
54
+ use Illuminate\D atabase\E loquent\B uilder;
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
+
56
81
Set a custom placeholder when no items are selected
57
82
58
83
``` PHP
0 commit comments