Skip to content

Commit eb9424b

Browse files
Update README.md
1 parent 28fd141 commit eb9424b

File tree

1 file changed

+70
-20
lines changed

1 file changed

+70
-20
lines changed

README.md

Lines changed: 70 additions & 20 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-
The multi-level select field lets you pick one or multiple options from a list that's neatly organized into different levels. It's all made possible with [TreeSelectJS](https://github.com/dipson88/treeselectjs).
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.
77

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

@@ -14,6 +14,9 @@ You can install the package via composer:
1414

1515
```bash
1616
composer require codewithdennis/filament-select-tree
17+
```
18+
19+
```bash
1720
php artisan filament:assets
1821
```
1922

@@ -24,62 +27,109 @@ php artisan filament:assets
2427
- BelongsTo Integration: Establish connections within your data effortlessly.
2528
- BelongsToMany Integration: Simplify the management of complex relationships through BelongsToMany integration.
2629

27-
🐛 One thing I have noticed about this project is that it tends to run a lot of queries, mainly because of its recursive design. Working to fix this in the upcoming updates.
30+
__🔍 One thing I've noticed is that it runs a lot of queries, mainly because of its recursive design. Working on reducing this in the upcoming updates to make it faster!__
2831

2932
## Usage
3033

34+
Import the `SelectTree` class from the `CodeWithDennis\FilamentSelectTree` namespace
35+
3136
```PHP
3237
use CodeWithDennis\FilamentSelectTree\SelectTree;
38+
```
39+
40+
Create a tree based on a 'BelongsToMany' relationship
3341

34-
// Create a tree based on a 'BelongsToMany' relationship
42+
```PHP
3543
SelectTree::make('categories')
3644
->relationship('categories', 'name', 'parent_id', function ($query) {
3745
return $query;
3846
})
47+
```
48+
49+
Create a tree based on a 'BelongsTo' relationship
3950

40-
// Create a tree based on a 'BelongsTo' relationship
51+
```PHP
4152
SelectTree::make('category_id')
4253
->relationship('category', 'name', 'parent_id', function ($query) {
4354
return $query;
4455
})
56+
```
57+
58+
Set a custom placeholder when no items are selected
59+
60+
```PHP
61+
->placeholder(__('Please select a category'))
62+
```
4563

46-
// Set a custom placeholder when no items are selected
47-
->placeholder(__('Enter your custom placeholder here'))
64+
Enable the selection of groups
4865

49-
// Enable the selection of groups
66+
```PHP
5067
->enableBranchNode()
68+
```
5169

52-
// Customize the label when there are zero search results
53-
->emptyLabel(__('No results found'))
70+
Customize the label when there are zero search results
71+
72+
```PHP
73+
->emptyLabel(__('Oops, no results have been found!'))
74+
```
5475

55-
// Display the count of children alongside the group's name
76+
Display the count of children alongside the group's name
77+
78+
```PHP
5679
->withCount()
80+
```
5781

58-
// Keep the dropdown open at all times
82+
Keep the dropdown open at all times
83+
84+
```PHP
5985
->alwaysOpen()
86+
```
6087

61-
// Set nodes as dependent
88+
Set nodes as dependent
89+
90+
```PHP
6291
->independent(false)
92+
```
6393

64-
// Set the parent's null value to -1, allowing you to use -1 as a sentinel value (default = null)
65-
->parentNullValue(-1)
94+
Expand the tree with selected values (only works if field is dependent)
6695

67-
// Expand the tree with selected values
96+
```PHP
6897
->expandSelected(false)
98+
```
99+
100+
Set the parent's null value to -1, allowing you to use -1 as a sentinel value (default = null)
69101

70-
// All groups will be opened to this level
102+
```PHP
103+
->parentNullValue(-1)
104+
```
105+
106+
All groups will be opened to this level
107+
108+
```PHP
71109
->defaultOpenLevel(2)
110+
```
111+
112+
Specify the list's force direction. Options include: auto (default), top, and bottom.
72113

73-
// Specify the list's force direction. Options include: auto (default), top, and bottom.
114+
```PHP
74115
->directon('top')
116+
```
117+
118+
Display individual leaf nodes instead of the main group when all leaf nodes are selected
75119

76-
// Display individual leaf nodes instead of the main group when all leaf nodes are selected
120+
```PHP
77121
->grouped(false)
122+
```
123+
124+
Hide the clearable icon
78125

79-
// Hide the clearable icon
126+
```PHP
80127
->clearable(false)
128+
```
129+
130+
Activate the search functionality
81131

82-
// Activate the search functionality for the SelectTree
132+
```PHP
83133
->searchable();
84134
```
85135

0 commit comments

Comments
 (0)