FilamentF
Filament3y ago
Remi

Repeater BelongsToMany not working on edit form

i followed the steps from the docs: https://filamentphp.com/docs/3.x/forms/fields/repeater#integrating-with-a-belongstomany-eloquent-relationship

This works on creation, but on the edit form it only shows a single record, not all the items.

On the Client Resource:

             Forms\Components\Repeater::make('clientLocations')
                    ->relationship()
                    ->simple(
                        Forms\Components\Select::make('location_id')
                            ->relationship('location', 'name')
                            ->required()
                    )
                    ->columns(1),


ClientLocation Pivot model has:
    public function client(): BelongsTo
    {
        return $this->belongsTo(Client::class);
    }

    public function location(): BelongsTo
    {
        return $this->belongsTo(Location::class);
    }


Also when I submit the edit page and change the single record it shows, it gives an error:
update
  `client_location`
SET
  `location_id` = 3
WHERE
  `` = 39
  AND `` = 39
Was this page helpful?