Can't access current Item in Repeater when delete action is called.

Instead i'm getting all the items with thier UUIDs
Repeater::make('app_screens')
->hiddenLabel()
->lazy()
->cloneable()
->collapsible()
->collapsed()
->reorderableWithButtons()
->itemLabel(fn(array $state) => @$state['title'])
->deleteAction(function (ComponentsAction $action, array $state) {
//can't access the current Item that is being deleted
/**
* dump($state);
* array:2 [▼
* "7b73c556-3780-4d89-8228-14b326df6104" => array:10 [▶]
* "317a8891-2a86-4e92-b9ce-096365ae9f87" => array:10 [▶]
* ]
* */
return $action->requiresConfirmation();
})
Repeater::make('app_screens')
->hiddenLabel()
->lazy()
->cloneable()
->collapsible()
->collapsed()
->reorderableWithButtons()
->itemLabel(fn(array $state) => @$state['title'])
->deleteAction(function (ComponentsAction $action, array $state) {
//can't access the current Item that is being deleted
/**
* dump($state);
* array:2 [▼
* "7b73c556-3780-4d89-8228-14b326df6104" => array:10 [▶]
* "317a8891-2a86-4e92-b9ce-096365ae9f87" => array:10 [▶]
* ]
* */
return $action->requiresConfirmation();
})
is there a way to somehow inject at-least uuid of the deletable item in deleteAction() so i can also delete from DB. thanks in advance.
No description
Solution:
@toeknee thank you: but i end up doing my own way here : ```php $updatedScreenIds = collect($screens)->map(fn(array $screen) => $screen['id'])->values();...
Jump to solution
2 Replies
toeknee
toeknee12mo ago
That is a strange request, but what you can do is write a cleanup function in a model observer, on update, check what has changed and remove whatever you usually insert from the dirty check. Does that make sense?
Solution
RizwanNasir
RizwanNasir12mo ago
@toeknee thank you: but i end up doing my own way here :
$updatedScreenIds = collect($screens)->map(fn(array $screen) => $screen['id'])->values();
$this->user->introScreens()->whereNotIn('id', $updatedScreenIds)
->with('media')
->delete();
$updatedScreenIds = collect($screens)->map(fn(array $screen) => $screen['id'])->values();
$this->user->introScreens()->whereNotIn('id', $updatedScreenIds)
->with('media')
->delete();
just checking the again for records that are not present in updatedList but in the database then deleting them. until we have any official way of doing it.
Want results from more Discord servers?
Add your server