#Nested HasMany Repeater – deleteAction always receives parent record instead of child

9 messages · Page 1 of 1 (latest)

torpid jetty
#

Hey everyone 👋

I have a nested Repeater setup — basically a HasMany inside another HasMany.
When I call ->deleteAction($record) on the inner repeater and dd($record) inside the action’s body, I always get the parent record, not the specific child item that was deleted.

This makes it impossible to check certain conditions before deleting a specific child.

Has anyone run into this before or found a way to access the actual child record inside the delete action of a nested repeater?

Thanks in advance 🙏

willow estuaryBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

worthy quiver
#

Can you provide the full code? Might need to use $state.

torpid jetty
#

It is basicaly this code:

Repeater::make('frameworkGoals')
    ->hiddenLabel()
    ->relationship('frameworkGoals')
    ->deleteAction(fn ($record) => dd($record)) // is returning the schema model (in my case ActionPlan) but I need the FrameworkGoal
    ->schema([
        Repeater::make('targetGoals')
            ->hiddenLabel()
            ->relationship('targetGoals')
            ->deleteAction(fn ($record) => dd($record)) // is returning the parent model (in my case FrameworkGoal) but I need the TargetGoal
            ->schema([]),
    ])

worthy quiver
#

So the delete action will do that as fn($record), is the parent record as you passed it in, what I think you'll want is:

->deleteAciton(fn($action) => $action->action(fn($record) => dd($record)))

I think

torpid jetty
#

That makes sense. I will try that later. 🤔

hushed light
torpid jetty