Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithDennis authored Nov 11, 2023
1 parent a04d3c2 commit b6c7b11
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ composer require codewithdennis/filament-select-tree
php artisan filament:assets
```

## Features

- Dark Mode: It seamlessly supports both Filament's light and dark modes out of the box.
- Search: Searching is fully supported, and it seamlessly searches through all levels within the tree structure.
- BelongsTo Integration: Establish connections within your data effortlessly.
- BelongsToMany Integration: Simplify the management of complex relationships through BelongsToMany integration.

## Usage

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

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


```bash
use Filament\Tables\Filters\Filter;
use Illuminate\Database\Eloquent\Builder;
```

```php
->filters([
Filter::make('tree')
->form([
SelectTree::make('categories')
->relationship('categories', 'name', 'parent_id')
->independent(false)
->enableBranchNode(),
])
->query(function (Builder $query, array $data) {
return $query->when($data['categories'], function ($query, $categories) {
return $query->whereHas('categories', fn($query) => $query->whereIn('id', $categories));
});
})
->indicateUsing(function (array $data): ?string {
if (! $data['categories']) {
return null;
}

return __('Categories') . ': ' . implode(', ', Category::whereIn('id', $data['categories'])->get()->pluck('name')->toArray());
})
])
```

Set a custom placeholder when no items are selected

```PHP
Expand Down

0 comments on commit b6c7b11

Please sign in to comment.