Hasan Tahseen
Hasan Tahseen
FFilament
Created by Hasan Tahseen on 5/31/2025 in #❓┊help
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 keys in the evaluate method have value of $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;
}
6 replies
FFilament
Created by Hasan Tahseen on 5/29/2025 in #❓┊help
Select Field Relationship have no limit
I have over 1M record for projects table. when I use the code below it will get all the projects without any limit for it which making the website not responding.
Forms\Components\Select::make('project_id')
->searchable()
->relationship('project', 'title')
Forms\Components\Select::make('project_id')
->searchable()
->relationship('project', 'title')
In order to make the select works I need to explicitly use limit in options and getSearchResultsUsing
Forms\Components\Select::make('project_id')
->searchable()
->options(Project::limit(10)->get()->pluck('title', 'id'))
->getSearchResultsUsing(function (?string $search) {
return Project::where('title', 'like', "%{$search}%")->limit(10)->get()->pluck('title', 'id');
})
Forms\Components\Select::make('project_id')
->searchable()
->options(Project::limit(10)->get()->pluck('title', 'id'))
->getSearchResultsUsing(function (?string $search) {
return Project::where('title', 'like', "%{$search}%")->limit(10)->get()->pluck('title', 'id');
})
is there any better way to do it? and why there is no limit in relationship method?
13 replies
FFilament
Created by Hasan Tahseen on 5/18/2025 in #❓┊help
Test Pagination options 10,20,50,100
No description
2 replies