F
Filamentβ€’4w ago
igorclauss

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

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 πŸ™
8 Replies
toeknee
toekneeβ€’4w ago
Can you provide the full code? Might need to use $state.
igorclauss
igorclaussOPβ€’4w ago
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([]),
])
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([]),
])
toeknee
toekneeβ€’4w ago
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)))
->deleteAciton(fn($action) => $action->action(fn($record) => dd($record)))
I think
igorclauss
igorclaussOPβ€’4w ago
That makes sense. I will try that later. πŸ€”
LeandroFerreira
LeandroFerreiraβ€’4w ago
hum, not sure if you can access the record, but I think you can access the itemState
->deleteAction(fn (Action $action) => $action
->action(function (array $arguments, Repeater $component) {
$itemData = $component->getItemState($arguments['item']);
})
)
->deleteAction(fn (Action $action) => $action
->action(function (array $arguments, Repeater $component) {
$itemData = $component->getItemState($arguments['item']);
})
)
example
igorclauss
igorclaussOPβ€’4w ago
Wow, thanks. How did I miss that in the docs? I actually read this chapter... πŸ€¦β€β™‚οΈ
LeandroFerreira
LeandroFerreiraβ€’4w ago
no problem πŸ™‚
toeknee
toekneeβ€’4w ago
Get spot Leandro!

Did you find this page helpful?