Skip to content

Commit 5150ea0

Browse files
Update README.MD
1 parent 0a6ff51 commit 5150ea0

File tree

2 files changed

+39
-64
lines changed

2 files changed

+39
-64
lines changed

README.md

Lines changed: 39 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/codewithdennis/filament-select-tree.svg?style=flat-square)](https://packagist.org/packages/codewithdennis/filament-select-tree)
44
[![Total Downloads](https://img.shields.io/packagist/dt/codewithdennis/filament-select-tree.svg?style=flat-square)](https://packagist.org/packages/codewithdennis/filament-select-tree)
55

6-
This is a package that allows you to create an interactive select tree field based on relationships in your Laravel / Filament application. It provides a convenient way to build hierarchical selection dropdowns with various customization options.
6+
This package adds a dynamic select tree field to your Laravel / Filament application, allowing you to create interactive hierarchical selection dropdowns based on relationships. It's handy for building selection dropdowns with various customization options.
77

88
![Select Tree](https://github.com/CodeWithDennis/filament-select-tree/assets/23448484/d944b896-134b-414a-b654-9adecc43ba5e)
99

@@ -20,63 +20,27 @@ composer require codewithdennis/filament-select-tree
2020
php artisan filament:assets
2121
```
2222

23-
## Usage
23+
## Relationships
2424

25-
Import the `SelectTree` class from the `CodeWithDennis\FilamentSelectTree` namespace
25+
#### Use the tree for a `BelongsToMany` relationship
2626

2727
```PHP
2828
use CodeWithDennis\FilamentSelectTree\SelectTree;
29-
```
30-
31-
Create a tree based on a 'BelongsToMany' relationship
3229

33-
```PHP
3430
SelectTree::make('categories')
35-
->relationship('categories', 'name', 'parent_id', function ($query) {
36-
return $query;
37-
})
31+
->relationship('categories', 'name', 'parent_id')
3832
```
3933

40-
Create a tree based on a 'BelongsTo' relationship
34+
#### Use the tree for a `BelongsTo` relationship
4135

4236
```PHP
37+
use CodeWithDennis\FilamentSelectTree\SelectTree;
38+
4339
SelectTree::make('category_id')
44-
->relationship('category', 'name', 'parent_id', function ($query) {
45-
return $query;
46-
})
40+
->relationship('category', 'name', 'parent_id')
4741
```
4842

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-
```
43+
## Methods
8044

8145
Set a custom placeholder when no items are selected
8246

@@ -162,35 +126,46 @@ Disable specific options in the tree
162126
->disabledOptions([2, 3, 4])
163127
```
164128

165-
```PHP
166-
->disabledOptions(function () {
167-
return Category::where('is_disabled', true)
168-
->get()
169-
->pluck('id')
170-
->toArray();
171-
})
172-
173-
```
174129
Hide specific options in the tree
175130

176131
```PHP
177132
->hiddenOptions([2, 3, 4])
178133
```
179134

180-
```PHP
181-
->hiddenOptions(function () {
182-
return Category::where('is_hidden', true)
183-
->get()
184-
->pluck('id')
185-
->toArray();
186-
})
135+
## Filters
136+
Use the tree in your table filters. Here's an example to show you how.
137+
138+
```bash
139+
use Filament\Tables\Filters\Filter;
140+
use Illuminate\Database\Eloquent\Builder;
141+
use CodeWithDennis\FilamentSelectTree\SelectTree;
187142
```
188143

144+
```php
145+
->filters([
146+
Filter::make('tree')
147+
->form([
148+
SelectTree::make('categories')
149+
->relationship('categories', 'name', 'parent_id')
150+
->independent(false)
151+
->enableBranchNode(),
152+
])
153+
->query(function (Builder $query, array $data) {
154+
return $query->when($data['categories'], function ($query, $categories) {
155+
return $query->whereHas('categories', fn($query) => $query->whereIn('id', $categories));
156+
});
157+
})
158+
->indicateUsing(function (array $data): ?string {
159+
if (! $data['categories']) {
160+
return null;
161+
}
189162

163+
return __('Categories') . ': ' . implode(', ', Category::whereIn('id', $data['categories'])->get()->pluck('name')->toArray());
164+
})
165+
])
166+
```
190167
## Screenshots
191-
192-
<img width="641" alt="light" src="https://github.com/CodeWithDennis/filament-select-tree/assets/23448484/4d348c85-5ee9-45b1-9424-0d8b3efcc02e">
193-
<img width="649" alt="dark" src="https://github.com/CodeWithDennis/filament-select-tree/assets/23448484/396627ff-bf36-44b7-b20c-0d32b2eff957">
168+
![download.png](./resources/images/example.png)
194169

195170
## Changelog
196171
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

resources/images/example.png

162 KB
Loading

0 commit comments

Comments
 (0)