Multiple select displays only one item
I have a select that allows multiple elements to be selected (they are currently in Edit).
My select has selected elements id: 29,5
Which in the Platform table corresponds to: Xbox Series X, PC.
He in the panel instead, shows me only Xbox Series X, fetching only one element.
4 Replies
I'm a little confused. Your 'platform' relationship is a BelongsTo, so by definition can only have a single selection.
And not sure what that extraInputAttributes is for?
If you want to select mutiple options, you need to use ->multiple(), and the relationship itself has to be a BelongsToMany (or some other "many" relationship).
I too am confused @Hugh Messenger 😂,
with:
I get the error:
>Filament\Forms\Components\Select::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\BelongsToMany|Znck\Eloquent\Relations\BelongsToThrough|null, Illuminate\Database\Eloquent\Relations\HasMany returned
He pointed out the relationship needs to be a BelongsToMany, not HasMany
It wouldn't be a HasMany.
It seems like what you need is a pivot table between whatever the model you are building this form on is, and the Platform model, so you can use a HasMany.
https://laravel.com/docs/10.x/eloquent-relationships#many-to-many
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.