© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•9mo ago•
5 replies
Hasan Tahseen

Confusing Attributes in getSearchResults Method For Select From Field

I came across this code in filament v3
public function getSearchResults(string $search): array
{
    if (! $this->getSearchResultsUsing) {
        return [];
    }

    $results = $this->evaluate($this->getSearchResultsUsing, [
        'query' => $search,
        'search' => $search,
        'searchQuery' => $search,
    ]);

    if ($results instanceof Arrayable) {
        $results = $results->toArray();
    }

    return $results;
}
public function getSearchResults(string $search): array
{
    if (! $this->getSearchResultsUsing) {
        return [];
    }

    $results = $this->evaluate($this->getSearchResultsUsing, [
        'query' => $search,
        'search' => $search,
        'searchQuery' => $search,
    ]);

    if ($results instanceof Arrayable) {
        $results = $results->toArray();
    }

    return $results;
}


My question is why the
query and search and searchQuery
query and search and searchQuery
keys in the evaluate method have value of
$search
$search
? this is confusing especially when I use query I expected a query builder not a search value. its need some refactoring on the values side or on the keys side of the array. Any suggestion or explanation for this part? I would suggest to make it look like this
public function getSearchResults(string $search): array
{
    if (! $this->getSearchResultsUsing) {
        return [];
    }

    $relationship = Relation::noConstraints(fn() => $this->getRelationship());

    $relationshipQuery = app(RelationshipJoiner::class)->prepareQueryForNoConstraints($relationship);

    $results = $this->evaluate($this->getSearchResultsUsing, [
        'query' => $relationshipQuery,
        'search' => $search,
    ]);

    if ($results instanceof Arrayable) {
        $results = $results->toArray();
    }

    return $results;
}
public function getSearchResults(string $search): array
{
    if (! $this->getSearchResultsUsing) {
        return [];
    }

    $relationship = Relation::noConstraints(fn() => $this->getRelationship());

    $relationshipQuery = app(RelationshipJoiner::class)->prepareQueryForNoConstraints($relationship);

    $results = $this->evaluate($this->getSearchResultsUsing, [
        'query' => $relationshipQuery,
        'search' => $search,
    ]);

    if ($results instanceof Arrayable) {
        $results = $results->toArray();
    }

    return $results;
}
Solution
I would suggest to make it look like this
You can implement this in your code, right? I don't think the change will happen because it's a breaking change.
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Displaying nested attributes on Select relationship field
FilamentFFilament / ❓┊help
2y ago
Troubleshooting $search variable accessibility in Select Field modifyQueryUsing() method
FilamentFFilament / ❓┊help
2y ago
HasManyThrough for select field
FilamentFFilament / ❓┊help
17mo ago
preload com getSearchResults
FilamentFFilament / ❓┊help
17mo ago