@@ -20,13 +20,6 @@ composer require codewithdennis/filament-select-tree
2020php 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
3225Import 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\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+
5681Set a custom placeholder when no items are selected
5782
5883``` PHP
0 commit comments