Weird behavior in nested repeater relationship

I noticed a weird side effect while trying to create a nested relationship with repeaters. When i add items to the relationship promo everything works correctly but as soon as the form fills again after submit it only shows 1 element. Refreshing the page shows the correct number of elements. postpromopreset is defined as a HasMany relationship on the Post model
postpromopreset_promo is defined as a HasMany relationship on the Postpromopreset model to a pivot model called PostpromopresetPromo I know the names are confusing but i'm still prototyping the entire thing, the idea is to create a series of preset of promos which then i can use inside the Post model in a select
Repeater::make('Promos')
->relationship(name: 'postpromopreset' )
->label('Presets')
->schema([
TextInput::make('name')
->label(__('Name')),
Repeater::make('promotions')
->label('Promo')
->relationship(name:'postpromopreset_promo')
->reorderable()
->reorderableWithDragAndDrop()
->reorderableWithButtons()
->orderColumn('order_column')
->schema([
Select::make('promo_id')
->relationship(
name:'promo',
titleAttribute:'title'
)
->disableOptionsWhenSelectedInSiblingRepeaterItems()

])
->grid(4)

])
Repeater::make('Promos')
->relationship(name: 'postpromopreset' )
->label('Presets')
->schema([
TextInput::make('name')
->label(__('Name')),
Repeater::make('promotions')
->label('Promo')
->relationship(name:'postpromopreset_promo')
->reorderable()
->reorderableWithDragAndDrop()
->reorderableWithButtons()
->orderColumn('order_column')
->schema([
Select::make('promo_id')
->relationship(
name:'promo',
titleAttribute:'title'
)
->disableOptionsWhenSelectedInSiblingRepeaterItems()

])
->grid(4)

])
Solution:
Update: I found out the issue was caused by me extending from Illuminate\Database\Eloquent\Relations\Pivot instead of Illuminate\Database\Eloquent\Model which caused this weird behavior
Jump to solution
4 Replies
ChesterS
ChesterS4w ago
Does the pivot table have a unique id ? Not a composite id (eg [column_1, column_2]) but a unique id-like column
Aivirth
AivirthOP3w ago
yes i always keep id primary keys on pivots because my current software to view database locks editing if it doesn't find a primary key, also it helps in these cases
Aivirth
AivirthOP3w ago
Update: i encountered the issue again in another repeater used as relationship, this time it was a far simpler one but still using a pivot. When i create multiple elements only the last one is shown until the page is refreshed. Specifically i'm using the workaround specified in https://filamentphp.com/docs/3.x/forms/fields/repeater#integrating-with-a-belongstomany-eloquent-relationship
Solution
Aivirth
Aivirth3w ago
Update: I found out the issue was caused by me extending from Illuminate\Database\Eloquent\Relations\Pivot instead of Illuminate\Database\Eloquent\Model which caused this weird behavior

Did you find this page helpful?