nova-searchable-select
nova-searchable-select copied to clipboard
make labelprefix searchable
Hey, thanks for this great field.
I have a question regarding the labelprefix. I use this as a way to show a relation owner in an Action:
SearchableSelect::make(__('Project'), 'id')
->resource(Project::class)
->label("title")
->labelPrefix("the_name")
On the Project resource:
Text::make('the_name', function () {
if ($this->user !== null) {
return $this->user->name;
}
return null;
}
Now when I search I can find the project, but the search is limited to the project's Title (label). I'd love to be able to say
->searchableLablePrefix()
or
->withMeta(['searchLabelPrefix' => true])
to include the labelprefix in the search.
If you don't plan on adding this as a feature could you hint me to a way to include the labelprefix in the search?
Thx C
The package uses the base Nova model's search function. If you want it to search a field, you need to add that field to the Nova model's $search
array like so.
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'code',
'title'
];
If you want to search a relation, you may need to pull in a package that allows you to search relations of a Nova model, like nova-search-relations. But editing this particular package to do that wouldn't be best practice, IMHO, since it already uses Nova's expected search functionality.