Skip to content

Commit cbbad83

Browse files
Format README
1 parent 32b7d93 commit cbbad83

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

README.md

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
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 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.
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
7+
building selection dropdowns with various customization options.
78

89
![thumbnail](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/thumbnail.jpg)
910

@@ -23,14 +24,14 @@ php artisan filament:assets
2324

2425
Use the tree for a `BelongsToMany` relationship
2526

26-
```PHP
27+
```php
2728
SelectTree::make('categories')
2829
->relationship('categories', 'name', 'parent_id')
2930
```
3031

3132
Use the tree for a `BelongsTo` relationship
3233

33-
```PHP
34+
```php
3435
SelectTree::make('category_id')
3536
->relationship('category', 'name', 'parent_id')
3637
```
@@ -39,14 +40,14 @@ SelectTree::make('category_id')
3940

4041
Customize the parent query
4142

42-
```PHP
43+
```php
4344
SelectTree::make('categories')
4445
->relationship(relationship: 'categories', titleAttribute: 'name', parentAttribute: 'parent_id', modifyQueryUsing: fn($query) => $query));
4546
```
4647

4748
Customize the child query
4849

49-
```PHP
50+
```php
5051
SelectTree::make('categories')
5152
->relationship(relationship: 'categories', titleAttribute: 'name', parentAttribute: 'parent_id', modifyChildQueryUsing: fn($query) => $query));
5253
```
@@ -55,126 +56,128 @@ SelectTree::make('categories')
5556

5657
Set a custom placeholder when no items are selected
5758

58-
```PHP
59+
```php
5960
->placeholder(__('Please select a category'))
6061
```
6162

6263
Enable the selection of groups
6364

64-
```PHP
65+
```php
6566
->enableBranchNode()
6667
```
6768

6869
Customize the label when there are zero search results
6970

70-
```PHP
71+
```php
7172
->emptyLabel(__('Oops, no results have been found!'))
7273
```
7374

7475
Display the count of children alongside the group's name
7576

76-
```PHP
77+
```php
7778
->withCount()
7879
```
7980

8081
Keep the dropdown open at all times
8182

82-
```PHP
83+
```php
8384
->alwaysOpen()
8485
```
8586

8687
Set nodes as dependent
8788

88-
```PHP
89+
```php
8990
->independent(false)
9091
```
9192

9293
Expand the tree with selected values (only works if field is dependent)
9394

94-
```PHP
95+
```php
9596
->expandSelected(false)
9697
```
9798

9899
Set the parent's null value to -1, allowing you to use -1 as a sentinel value (default = null)
99100

100-
```PHP
101+
```php
101102
->parentNullValue(-1)
102103
```
103104

104105
All groups will be opened to this level
105106

106-
```PHP
107+
```php
107108
->defaultOpenLevel(2)
108109
```
109110

110111
Specify the list's force direction. Options include: auto (default), top, and bottom.
111112

112-
```PHP
113+
```php
113114
->direction('top')
114115
```
115116

116117
Display individual leaf nodes instead of the main group when all leaf nodes are selected
117118

118-
```PHP
119+
```php
119120
->grouped(false)
120121
```
121122

122123
Hide the clearable icon
123124

124-
```PHP
125+
```php
125126
->clearable(false)
126127
```
127128

128129
Activate the search functionality
129130

130-
```PHP
131+
```php
131132
->searchable();
132133
```
133134

134135
Disable specific options in the tree
135136

136-
```PHP
137+
```php
137138
->disabledOptions([2, 3, 4])
138139
```
139140

140141
Hide specific options in the tree
141142

142-
```PHP
143+
```php
143144
->hiddenOptions([2, 3, 4])
144145
```
145146

146147
Allow soft deleted items to be displayed
147148

148-
```PHP
149+
```php
149150
->withTrashed()
150151
```
151152

152153
Specify a different key for your model.
153154
For example: you have id, code and parent_code. Your model uses id as key, but the parent-child relation is established between code and parent_code
154155

155-
```PHP
156+
```php
156157
->withKey('code')
157158
```
158159

159160
Store fetched models for additional functionality
160161

161-
```PHP
162+
```php
162163
->storeResults()
163164
```
164165

165166
Now you can access the results in `disabledOptions` or `hiddenOptions`
166167

167-
```PHP
168+
```php
168169
->disabledOptions(function ($state, SelectTree $component) {
169170
$results = $component->getResults();
170171
})
171172
```
172173

173-
By default, the type of selection in the tree (single or multiple) is determined by the relationship type: `BelongsTo` for single selection and `BelongsToMany` for multiple selection. If you want to explicitly set the selection type, use:
174+
By default, the type of selection in the tree (single or multiple) is determined by the relationship type: `BelongsTo` for single selection and `BelongsToMany` for multiple selection. If you want to
175+
explicitly set the selection type, use:
174176

175-
```PHP
176-
->multiple(false) //or true, Closure that returns boolean
177+
```php
178+
->multiple(false)
177179
```
180+
178181
If you need to prepend an item to the tree menu, use the `prepend` method. This method accepts an array or a closure. It is useful when the tree-select is used as a filter (see example below).
179182

180183
```php
@@ -192,22 +195,23 @@ use CodeWithDennis\FilamentSelectTree\SelectTree;
192195
->enableBranchNode()
193196
->multiple(false)
194197
->prepend([
195-
'name'=>'Uncategorized Products', //required
196-
'value'=>-1, //required
198+
'name' => 'Uncategorized Products',
199+
'value' => -1,
197200
'parent' => null // optional
198201
'disabled' => false // optional
199202
'hidden' => false // optional
200-
'children'=>[] //optional
203+
'children' => [] // optional
201204
])
202205
])
203206
->query(function (Builder $query, array $data) {
204207
$categories= [(int) $data['category']];
205-
return $query->when($data['category'], function ($query, $categories) {
206-
if($data['category']===-1){
208+
209+
return $query->when($data['category'], function (Builder $query, $categories) {
210+
if($data['category'] === -1){
207211
return $query->whereDoesntHave('categories');
208212
}
209213

210-
return $query->whereHas('categories', fn($query) => $query->whereIn('id', $categories));
214+
return $query->whereHas('categories', fn(Builder $query) => $query->whereIn('id', $categories));
211215
});
212216
})
213217
])
@@ -248,6 +252,7 @@ use CodeWithDennis\FilamentSelectTree\SelectTree;
248252
```
249253

250254
## Screenshots
255+
251256
![example-1](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-1.jpg)
252257
![example-2](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-2.jpg)
253258
![example-3](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-3.jpg)

0 commit comments

Comments
 (0)