Skip to content

Commit 27d7f48

Browse files
Updated CSS, Readme & removed some options
1 parent efe7362 commit 27d7f48

File tree

5 files changed

+26
-30
lines changed

5 files changed

+26
-30
lines changed

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,27 @@ php artisan filament:assets
2020
## Features
2121
- ✅ Compatible with dark mode
2222
- ✅ Featuring search functionality
23-
- ✅ Comma seperated multi-select
2423
- ✅ Custom options
24+
- ✅ Works with `BelongsTo` (single) and `BelongsToMany` (multiple)
25+
- ❌ Comma seperated multi-select
2526
- ❌ Disabled options (Planned)
26-
- ❌ Relationships (Planned)
2727

2828
## Usage
2929

3030
```PHP
3131
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) {
34-
return $query;
35-
})
3632

33+
// Create a tree based on a `BelongsToMany` relationship
34+
->relationship('categories', 'name', fn($query) => $query),
35+
36+
// Create a tree based on a `BelongsTo` relationship
37+
->relationship('category', 'name', fn($query) => $query),
38+
3739
// Set a custom placeholder for when no items are selected
3840
->placeholder(__('Your custom placeholder here'))
3941

40-
// Ensures that only leaf nodes can be selected while preventing the selection of groups.
41-
->disabledBranchNode()
42+
// Enabled the selection of groups.
43+
->enableBranchNode()
4244

4345
// Adjust the emptyLabel for when there are zero search results.
4446
->emptyLabel(__('No results found'))
@@ -67,6 +69,20 @@ SelectTree::make('category_id')
6769
// Activates the search functionality for the SelectTree.
6870
->searchable()
6971
```
72+
### Relationships (examples)
73+
74+
```PHP
75+
public function category(): BelongsTo
76+
{
77+
return $this->belongsTo(Category::class);
78+
}
79+
```
80+
```PHP
81+
public function categories(): belongsToMany
82+
{
83+
return $this->belongsToMany(Category::class);
84+
}
85+
```
7086
### Custom
7187
If you prefer to create custom options rather than utilizing a pre-existing model, you can achieve this using the following example:
7288

resources/css/custom.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ html.dark .treeselect-input__tags-element:hover svg {
212212
}
213213

214214
.treeselect-input__clear svg {
215-
stroke: rgb(255 255 255/var(--tw-text-opacity));
216215
opacity: 0.5;
217216
}
218217

resources/dist/custom.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/select-tree.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
isIndependentNodes: '{{ $getIndependent() }}',
2525
showTags: '{{ $getMultiple() }}',
2626
alwaysOpen: '{{ $getAlwaysOpen() }}',
27-
clearable: true,
27+
clearable: '{{ $getClearable() }}',
2828
emptyText: '{{ $getEmptyLabel() }}',
2929
expandSelected: '{{ $getExpandSelected() }}',
3030
grouped: '{{ $getGrouped() }}',

src/SelectTree.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class SelectTree extends Field
4141

4242
protected bool $grouped = true;
4343

44-
protected array $options = [];
45-
4644
protected string|Closure $relationship;
4745

4846
protected ?Closure $modifyQueryUsing;
@@ -84,11 +82,6 @@ protected function setUp(): void
8482

8583
private function buildTree(int $parent = null): array|Collection
8684
{
87-
// Check if options have already been set, if so, return them.
88-
if ($this->getOptions()) {
89-
return $this->getOptions();
90-
}
91-
9285
// Determine the foreign key based on the type of relationship.
9386
if ($this->getRelationship() instanceof BelongsTo) {
9487
$key = $this->getRelationship()->getForeignKeyName();
@@ -199,13 +192,6 @@ public function alwaysOpen(bool $alwaysOpen = true): static
199192
return $this;
200193
}
201194

202-
public function options(array $options): static
203-
{
204-
$this->options = $options;
205-
206-
return $this;
207-
}
208-
209195
public function enableBranchNode(bool $enableBranchNode = true): static
210196
{
211197
$this->enableBranchNode = $enableBranchNode;
@@ -253,11 +239,6 @@ public function getAlwaysOpen(): bool
253239
return $this->evaluate($this->alwaysOpen);
254240
}
255241

256-
public function getOptions(): array
257-
{
258-
return $this->evaluate($this->options);
259-
}
260-
261242
public function getEnableBranchNode(): bool
262243
{
263244
return $this->evaluate($this->enableBranchNode);

0 commit comments

Comments
 (0)