Error with 'multiple' Attribute in Select Input Field

Hi all, I need help with an error that pops up when I add the 'multiple' attribute to a select input field. Thanks for your assistance.
No description
10 Replies
MohamedSabil83
MohamedSabil839mo ago
You can't use ->multiple() with belongsTo relation
dynamite
dynamiteOP9mo ago
hmmm , whate relationship You can use in ->multiple()
MohamedSabil83
MohamedSabil839mo ago
belongsToMany relation or normal field casted as array
dynamite
dynamiteOP9mo ago
Oke , but not work Select::make('department_ids') ->multiple() ->preload() ->required() ->options( Department::all()->pluck("name", "id")) ])->columns(2), public function departments() { return $this->belongsToMany (Department::class); } This error has not changed
Dan Harrin
Dan Harrin9mo ago
you need a pivot table, not a foreign key column
dynamite
dynamiteOP9mo ago
How did he do that?
Dan Harrin
Dan Harrin9mo ago
please google "laravel belongs to many"
dynamite
dynamiteOP9mo ago
I don't mean that, I know how to do it in Larvel What I mean is how do I do it in the column
Dan Harrin
Dan Harrin9mo ago
a belongs to many relationship relies on a pivot table. not a JSON array of IDs. remove the relationship and fix the table column to be JSON
dynamite
dynamiteOP9mo ago
ok i try it

Did you find this page helpful?