CheckBoxList relationships error

When i add relationships in creating checkBoxList like shown in the code below :
Forms\Components\CheckboxList::make('speakers')
->relationship('speakers', 'name')
->options(Speaker::all()->pluck('name', 'id'))
->required() ,
Forms\Components\CheckboxList::make('speakers')
->relationship('speakers', 'name')
->options(Speaker::all()->pluck('name', 'id'))
->required() ,
This error occure : ❌ Filament\Forms\Components\CheckboxList::getRelationship(): Return value must be of type ?Illuminate\Database\Eloquent\Relations\BelongsToMany, Illuminate\Database\Eloquent\Relations\HasMany returned
No description
Solution:
Hi, you don't need to have following if you are using relationship ->options(Speaker::all()->pluck('name', 'id'))...
Jump to solution
2 Replies
Solution
Tieme
Tieme11mo ago
Hi, you don't need to have following if you are using relationship ->options(Speaker::all()->pluck('name', 'id')) Also the relationship must me BelongsToMany instead of HasMany on the relation (model)
AbderrahmenBns
AbderrahmenBnsOP11mo ago
Thank you it solved the issue
Want results from more Discord servers?
Add your server