You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+37-57
Original file line number
Diff line number
Diff line change
@@ -18,85 +18,65 @@ php artisan filament:assets
18
18
```
19
19
20
20
## Features
21
-
- ✅ Compatible with dark mode
22
-
- ✅ Featuring search functionality
23
-
- ✅ Comma seperated multi-select
24
-
- ✅ Custom options
25
-
- ❌ Disabled options (Planned)
26
-
- ❌ Relationships (Planned)
27
-
21
+
22
+
- Dark Mode: It seamlessly supports both Filament's light and dark modes out of the box.
23
+
- Search: Searching is fully supported, and it seamlessly searches through all levels within the tree structure.
24
+
- BelongsTo Integration: Establish connections within your data effortlessly.
25
+
- BelongsToMany Integration: Simplify the management of complex relationships through BelongsToMany integration.
26
+
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.
28
+
28
29
## Usage
29
30
30
31
```PHP
32
+
// Create a tree based on a 'BelongsToMany' relationship
33
+
SelectTree::make('categories')
34
+
->relationship('categories', 'name', 'parent_id', function ($query) {
35
+
return $query;
36
+
})
37
+
38
+
// Create a tree based on a 'BelongsTo' relationship
31
39
SelectTree::make('category_id')
32
-
// Creates a select tree with 'Category' model, using 'category_id' as parent and 'name' as label, allowing custom query modification.
33
-
->tree(Category::class, 'category_id', 'name', function ($query) {
40
+
->relationship('category', 'name', 'parent_id', function ($query) {
34
41
return $query;
35
42
})
36
43
37
-
// Set a custom placeholder for when no items are selected
38
-
->placeholder(__('Your custom placeholder here'))
44
+
// Set a custom placeholder when no items are selected
45
+
->placeholder(__('Enter your custom placeholder here'))
39
46
40
-
// Ensures that only leaf nodes can be selected while preventing the selection of groups.
41
-
->disabledBranchNode()
42
-
43
-
// Adjust the emptyLabel for when there are zero search results.
44
-
->emptyLabel(__('No results found'))
47
+
// Enable the selection of groups
48
+
->enableBranchNode()
45
49
46
-
// Show the count of children alongside the group's name.
47
-
->withCount()
50
+
// Customize the label when there are zero search results
51
+
->emptyLabel(__('No results found'))
48
52
49
-
// To keep the dropdown open at all times
50
-
->alwaysOpen()
53
+
// Display the count of children alongside the group's name
54
+
->withCount()
51
55
52
-
// By default, all nodes are independent.
53
-
->independent(false)
54
-
55
-
// When 'independent' is set to false, the tree will open with the selected values by default.
56
-
->expandSelected(false)
57
-
58
-
// Display individual leaf nodes instead of the main group when all leaf nodes are selected.
59
-
->grouped(false)
56
+
// Keep the dropdown open at all times
57
+
->alwaysOpen()
60
58
61
-
// By default, the clearable icon is enabled, but you can hide it with:
62
-
->clearable(false)
59
+
// Set nodes as dependent
60
+
->independent(false)
63
61
64
-
// Enable the option to save multiple values as a string (comma-separated)
65
-
->multiple()
62
+
// Expand the tree with selected values
63
+
->expandSelected(false)
66
64
67
-
// Activates the search functionality for the SelectTree.
68
-
->searchable()
69
-
```
70
-
### Custom
71
-
If you prefer to create custom options rather than utilizing a pre-existing model, you can achieve this using the following example:
65
+
// Display individual leaf nodes instead of the main group when all leaf nodes are selected
66
+
->grouped(false)
72
67
73
-
```PHP
74
-
->options([
75
-
[
76
-
'name' => 'Electronics',
77
-
'value' => 'electronics',
78
-
'children' => [
79
-
[
80
-
'name' => 'Mobile Devices',
81
-
'value' => 'mobile devices',
82
-
'children' => [
83
-
[
84
-
'name' => 'Apple Products',
85
-
'value' => 'apple products',
86
-
]
87
-
]
88
-
]
89
-
]
90
-
],
91
-
])
68
+
// Hide the clearable icon
69
+
->clearable(false)
70
+
71
+
// Activate the search functionality for the SelectTree
0 commit comments