bernhardh's avatar

Prefilled searchable nova belongsto field

Hello,

is there a way, to use a nova BelongsTo field with the searchable method, but prepopulate / prefill the selectbox with the available options?

I mean, lets say I in my article resource, I have a BelongsTo field with users:

BelongsTo::make('User', 'user', User::class)->searchable();

if a user clicks on the field, he should not only see the search-input, but as well the list of available option, similar to if we wouldn't have used the searchable() method.

0 likes
5 replies
philipbaginski's avatar

Select::make('Tags', 'tag_id') ->searchable() ->options(\App\Tag::all()->pluck('name', 'id')) ->displayUsingLabels(),

bernhardh's avatar

Nope. I stopped using nova and switched to filamentadmin. There it would be

Select::make("tag_id")->relationship("tag", "name")->searchable()->preload()

TheAnswerIsAlwaysMaybe's avatar

In case it helps someone: Just noticed that if the parent resource defines a fieldsForCreate() and that methods does NOT contain the HasMany relation, the BelongsTo field on your child resource does not pre-populate.

Without the fieldsForCreate(), the fields() method obviously should also define the HasMany field.

Please or to participate in this conversation.