Skip to content

Commit

Permalink
fix: Issue filters with enum
Browse files Browse the repository at this point in the history
Issue #1486
  • Loading branch information
lee-to committed Jan 20, 2025
1 parent 6e2641c commit 6c3bd4f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Laravel/src/Applies/Filters/SelectModelApply.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ public function apply(FieldContract $field): Closure
{
return static function (Builder $query) use ($field): void {
if (filled($field->getRequestValue())) {
$values = $field->getRequestValue();

$query->when(
$field->isMultiple(),
static fn (Builder $q) => $q->whereIn($field->getColumn(), $field->getRequestValue()),
static fn (Builder $q) => $q->where($field->getColumn(), $field->getRequestValue()),
static fn (Builder $q) => $q->whereIn($field->getColumn(), \is_string($values) ? explode(',', $values) : $values),
static fn (Builder $q) => $q->where($field->getColumn(), $values),
);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/src/Fields/Relationships/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ protected function resolveValue(): mixed
$this->memoizeValues = $this->getRelation()
?->getRelated()
?->newQuery()
?->findMany($this->toValue()) ?? EloquentCollection::make();
?->findMany(array_keys($this->toValue()->toArray())) ?? EloquentCollection::make();
}

if ($this->isSelectMode()) {
Expand Down
1 change: 1 addition & 0 deletions src/Laravel/src/MoonShineEndpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public function withRelation(
'resourceItem' => $resourceItem,
'_parent_field' => $parentField,
'_relation' => $relation,
'_no_items_query' => true,
]);
}
}
4 changes: 4 additions & 0 deletions src/Laravel/src/Pages/Crud/IndexPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ protected function getItemsComponent(iterable $items, Fields $fields): Component
*/
protected function getItemsComponents(): array
{
if(request()->has('_no_items_query')) {
return [];
}

$this->getResource()->setQueryParams(
request()->only($this->getResource()->getQueryParamsKeys())
);
Expand Down

0 comments on commit 6c3bd4f

Please sign in to comment.