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
MohamedSabil838mo ago
You can't use ->multiple() with belongsTo relation
dynamite
dynamiteOP8mo ago
hmmm , whate relationship You can use in ->multiple()
MohamedSabil83
MohamedSabil838mo ago
belongsToMany relation or normal field casted as array
dynamite
dynamiteOP8mo 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 Harrin8mo ago
you need a pivot table, not a foreign key column
dynamite
dynamiteOP8mo ago
How did he do that?
Dan Harrin
Dan Harrin8mo ago
please google "laravel belongs to many"
dynamite
dynamiteOP8mo 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 Harrin8mo 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
dynamiteOP8mo ago
ok i try it
Want results from more Discord servers?
Add your server