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();
});
})
->deleteAction(function ($action) {
// $action->requiresConfirmation();
$action->action(function ($state, array $arguments) {
$key = $arguments['item'];
$record = $state[$key];
$attachment = Attachment::findOrFail($record['id'])->delete();
});
})
No description
No description
Solution:
this works, deletes the item from the ui and with a custom delete statement ```php Repeater::make('Attachments') ->relationship('attachments')...
Jump to solution
1 Reply
Solution
gladjanus43
gladjanus435mo ago
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([...])
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([...])