Skip to content

Fix: allow enum filters on relation queries - #8

Merged
trippo merged 1 commit into
datomatic:mainfrom
RobertoNegro:fix/enum-filter-on-relation
Oct 6, 2026
Merged

trippo merged 1 commit into
datomatic:mainfrom
RobertoNegro:fix/enum-filter-on-relation

Conversation

@RobertoNegro

Copy link
Copy Markdown
Contributor

Problem

Applying EnumFilter or EnumBooleanFilter to a resource index rendered through a relation (e.g. a HasMany field on a detail page) throws:

TypeError: Datomatic\Nova\Fields\Enum\EnumBooleanFilter::apply(): Return value must be of type Illuminate\Database\Eloquent\Builder, Illuminate\Database\Eloquent\Relations\HasMany returned

Root cause

Nova may hand the filter an Illuminate\Database\Eloquent\Relations\Relation instead of a plain Builder. Relation::__call() forwards where() / whereIn() to the inner builder via forwardDecoratedCallTo(), which returns the relation itself, so the filter returns a HasMany, violating the : Builder return type.

Both classes implement Illuminate\Contracts\Database\Eloquent\Builder, the same type Nova's own Filter::apply() documents.

Fix

Return type widened from the concrete Eloquent builder to the contract it shares with relations. Two-line diff, behavior unchanged:

-use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Contracts\Database\Eloquent\Builder;

applied to src/EnumFilter.php and src/EnumBooleanFilter.php.

Verification

  • Reproduced the TypeError on a HasMany relation before the fix; after the fix both filters apply cleanly on Builder and HasMany, an empty boolean selection stays a no-op, and the generated SQL is unchanged.
  • php-cs-fixer --dry-run with the repo config: clean.
  • PHPStan level max: no new issues (3 pre-existing notices gone).

@trippo
trippo merged commit 75f3958 into datomatic:main Oct 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants