Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SunnyFlorida's avatar

Multi-select a BelongsToMany

How to multi-select a BelongsToMany value? I have tried multiple approaches, but must be missing something. Any terse example of the fields and model changes needed to enable this appreciated.

I am using https://github.com/optimistdigital/nova-multiselect-field which works very well for static values.

Thanks in advance!

0 likes
3 replies
saamretep's avatar

In the example I have a Note and Tags, where the Tas have a BelongsToMany relation.

I wasn't able to store the selected Tag id's in the separate note_tag table therefore added an extra column in the Note model where the id's are stored of the selected tags.

So I get all tags:

public function fields(Request $request)
    {
        $tags = \App\Tag::all()->pluck('name', 'id');

Then

Multiselect::make('Tags', 'tags')
                ->options($tags)
                ->placeholder('Kies een of meerdere tags'),

That worked for me nevertheless I can't add the tags column to the search as it stores the id's. And using a filter with dynamic values is not working as well.

saamretep's avatar

I've changed my Tags table to:

Schema::create('tags', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('key');
            $table->string('value');
            $table->timestamps();
        });

Using the following stores the vales instead of the ids

public function fields(Request $request)
    {
        $tags = \App\Tag::all()->pluck('key', 'value');

Now you can use search on the tags as well.

kevinbui's avatar

This is an old thread, but I just happened to resolve the very same problem in Nova.

We can simply use the searchable method:

use Laravel\Nova\Fields\BelongsToMany;

BelongsToMany::make('Your Field')->searchable();

Please or to participate in this conversation.