FilamentF
Filament11mo ago
Aivirth

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)

  ])
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
Was this page helpful?