How can I get the ID of the deleted item in a repeater action?

I can't work out how to get the ID of the deleted item in the delete action that is attached to my repeater. The $state parameter has the entire state of the repeater (e.g. all items), have I attached my action to the wrong component perhaps? Code looks like this... ```Repeater::make('eventQuestionnaires') ->label(__('Questionnaires')) ->relationship() ->deleteAction( function (Action $action) { $action->requiresConfirmation() ->action(function(Repeater $component, callable $get, $state){ ray($component); ray($state); }) ->modalSubmitActionLabel('Remove'); }, ) ->schema([
7 Replies
Dan Harrin
Dan Harrin15mo ago
@.charliefortune what is the goal here once you have the ID
charliefortune
charliefortuneOP15mo ago
My architecture is client>api - so I need to do more than just kill the member of the collection in the local db. I want the ID so I can post the delete request back to the api, then I will remove the local record depending on the api response. Once I've got a reference to the current item, I can do the rest
Dan Harrin
Dan Harrin15mo ago
deleting doesnt happen until the form is saved the delete action only removes the item from the temporary array before its saves
Dan Harrin
Dan Harrin15mo ago
so... 1) to answer your question, source dive Repeater.php - https://github.com/filamentphp/filament/blob/3.x/packages/forms/src/Components/Repeater.php#L205-L210. You see $arguments['item']? that's the array key we're deleting 2) if you want to delete on save, you should use an observer and ->getOriginal() on the model to compare the keys that were deleted, probably
GitHub
filament/packages/forms/src/Components/Repeater.php at 3.x · filame...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
charliefortune
charliefortuneOP15mo ago
I don't have any kind of form save - everything else saves on update events. I could compare the collection, but that seems a bit clunky. But if I can get the
$arguments
$arguments
into my closure then I should be able to get the item from there, I guess. a related issue is how to update the collection with the properties of the record once it has been persisted in the api and locally - I get a record back from the api and insert it locally. But in order to capture further updates to that repeater item, I need to add the new ID into the in-memory item. I guess I will do this in a similar way - manipulate the collection. Is there an easy way to reload the collection from the underlying relationship? I could just refesh my repeater, you see.
Dan Harrin
Dan Harrin15mo ago
you see how we do $component->state() $component->loadStateFromRelationships() source diving is your friend, if you have a good IDE
charliefortune
charliefortuneOP15mo ago
yeah cool, thanks for your help 👍
Want results from more Discord servers?
Add your server