Search code examples
laravellaravel-nova

Laravel Nova Multiselect (on create Error Array to string)


I try using multiselect when creating record but I get error Array to String. But when I update record everything is ok.

            Panel::make('Material', [
            MultiSelect::make('Select materials', 'material_id')
                ->options(Material::orderBy('name', 'ASC')->get()->pluck('name', 'id'))
                ->hideFromIndex(),
        ]),

I need hide this filed when creating record to use him on update.

Thanks.


Solution

  • What database type is material_id? Make sure it's a database field that allows to save array's.

    One other thing that could cause this if you didn't cast the field in your model to array

    <?php
    
    namespace App\Models;
    
    class Model
    {
        protected $casts = [
            'material_id' => 'array',
        ];
    }