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

acrm's avatar
Level 1

Laravel Nova - Populate options of a multiselect

Hi all,

I am trying to populate options for a MultiSelect in Laravel Nova (4.~) using the following code:

            MultiSelect::make('Rights')
                ->options(function() {
                    $rights = \App\Models\Right::all();

                    $options = [];

                    foreach($rights as $right) {
                        $options[$right->id] = $right->name;
                    }

                    return $options;
                })
                ->displayUsingLabels(),

When trying it, Nova returns me "Array to string conversion" and "There was a problem submitting the form". Any ideas on how to solve it? I try to have all $right-name (s) in the options array as I do not know how to do it differently.

Thank you!

0 likes
2 replies
acrm's avatar
Level 1

Because I just came across it in the application again, this is the output I get when just viewing it (not editing): [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

acrm's avatar
Level 1

In addition to the condition above, I came across the same problem when trying to query a relationship between different objects on the same model

            MultiSelect::make('Sub Entries')
                ->options(function () {
                    $entries= Entry::where('type', 'master')->get();
                    $options = [];
                    foreach ($entries as $entry) {
                        $options[$entry->id] = $entry->name;
                    }
                    return $options;
                }),

In this case I receive the following error:

[previous exception] [object] (PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'requirements.master_id' in 'where clause' at C:\xampp\htdocs\test\vendor\laravel\framework\src\Illuminate\Database\Connection.php:397) [stacktrace]

#0 C:\xampp\htdocs\test\vendor\laravel\framework\src\Illuminate\Database\Connection.php(397): PDO->prepare('select * from `...') [...]

I know I am doing some essential stuff wrong. Any remark for me? Thank you!

Please or to participate in this conversation.