Delete repeater items from UI and database at the same time

Inside of the edit action of a relationmanager I have a repeater form. Everything is working correct but now I need to delete the items. From a UX standpoint I dont like it that a user needs to press Save before the item is actually deleted. I have tried some things where the item is deleted from the database but then the UI is not updated.

Then the other option is to use the standard delete but then you need to press save which in my opinion is not needed. Does anybody have a solution where both requirements are met?

I have tried this in my code:

->deleteAction(function ($action) {
    // $action->requiresConfirmation();
    $action->action(function ($state, array $arguments) {
        $key = $arguments['item'];
        $record = $state[$key];
        $attachment = Attachment::findOrFail($record['id'])->delete();
    });
})
Screenshot_2023-12-18_at_12.38.29.png
Screenshot_2023-12-18_at_12.38.38.png
Solution
this works, deletes the item from the ui and with a custom delete statement

Repeater::make('Attachments')
                ->relationship('attachments')
                ->columns(2)
                ->hiddenLabel()
                ->deleteAction(
                    function ($action) {
                        $action->requiresConfirmation();
                        $action->before(function (array $arguments, Repeater $component) {
                            $itemData = $component->getItemState($arguments['item']);
                            AttachmentService::deleteAttachment(Attachment::find($itemData['id']));
                        });
                    }
                )
                ->schema([...])
Was this page helpful?