Skip to content

Commit 9ea82ec

Browse files
committed
merging
2 parents 6e72eea + 91122f9 commit 9ea82ec

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,12 @@ use CodeWithDennis\FilamentSelectTree\SelectTree;
204204
])
205205
])
206206
->query(function (Builder $query, array $data) {
207-
$categories = [(int) $data['category']];
208-
209-
return $query->when($data['category'], function (Builder $query, $categories) {
210-
if($data['category'] === -1){
211-
return $query->whereDoesntHave('categories');
207+
return $query->when($data['categories'], function (Builder $query, $categories) {
208+
if (collect($categories)->contains('-1')) {
209+
$query->whereDoesntHave('categories');
212210
}
213-
214-
return $query->whereHas('categories', fn(Builder $query) => $query->whereIn('id', $categories));
211+
return $query->orWhereHas('categories',
212+
fn(Builder $query) => $query->whereIn('id', $categories));
215213
});
216214
})
217215
])

resources/dist/filament-select-tree.js

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/js/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,21 @@ export default function selectTree({
2727
/** @type Treeselect */
2828
tree: null,
2929

30+
formatState: function (state) {
31+
if (Array.isArray(state)) {
32+
return (state ?? []).map((item) => item?.toString())
33+
}
34+
35+
return state?.toString()
36+
},
37+
38+
3039
init() {
3140
this.tree = new Treeselect({
3241
id: `tree-${name}-id`,
3342
ariaLabel: `tree-${name}-label`,
3443
parentHtmlContainer: this.$refs.tree,
35-
value: this.state,
44+
value: this.formatState(this.state),
3645
options,
3746
searchable,
3847
showCount,

src/SelectTree.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ private function buildNode($result, $resultMap, $disabledOptions, $hiddenOptions
228228
// Create a node with 'name' and 'value' attributes
229229
$node = [
230230
'name' => $result->{$this->getTitleAttribute()},
231-
'value' => $key,
232-
'parent' => $result->{$this->getParentAttribute()},
231+
'value' => (string) $key,
232+
'parent' => (string) $result->{$this->getParentAttribute()},
233233
'disabled' => in_array($key, $disabledOptions),
234234
'hidden' => in_array($key, $hiddenOptions),
235235
];
@@ -312,6 +312,7 @@ public function prepend(Closure|array|null $prepend = null): static
312312
return $this;
313313
}
314314

315+
315316
public function getRelationship(): BelongsToMany|BelongsTo
316317
{
317318
return $this->getModelInstance()->{$this->evaluate($this->relationship)}();
@@ -449,7 +450,7 @@ public function getIndependent(): bool
449450

450451
public function getCustomKey($record): string
451452
{
452-
$key = is_null($this->customKey) ? $record->getKey() : $record->{$this->customKey};
453+
$key = is_null($this->customKey) ? $record->getKey() : $record->{$this->customKey};
453454

454455
return (string) $key;
455456
}
@@ -622,15 +623,4 @@ public function createOptionModalHeading(string|Closure|null $heading): static
622623

623624
return $this;
624625
}
625-
626-
public function getState(): mixed
627-
{
628-
$state = parent::getState();
629-
630-
if (is_array($state)) {
631-
return array_map(fn ($value) => (string) $value, $state);
632-
}
633-
634-
return (string) $state;
635-
}
636626
}

0 commit comments

Comments
 (0)