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
modelpostpromopreset_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
Solution:Jump to 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 behavior4 Replies
Does the pivot table have a unique id ? Not a composite id (eg
[column_1, column_2]
) but a unique id
-like columnyes 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
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
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