nova-searchable-select icon indicating copy to clipboard operation
nova-searchable-select copied to clipboard

make labelprefix searchable

Open ChrisEbner opened this issue 5 years ago • 1 comments

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

ChrisEbner avatar Feb 21 '20 16:02 ChrisEbner

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.

cotrudel avatar Feb 26 '20 21:02 cotrudel