Access model data on delete action
I have an odd use case where my model is a remote API resource via calebporzio/sushi. Everything is working great from editing, creating, viewing -- but not deleting. For editing I'm utilizing
EditAction::make()->using
which references a method on my model that performs the update via API.
For delete however, I can't find a way to pass any data of the actual model being deleted so that I can facilitate this on my own on the backend.
DeleteAction::make()->after()
does not appear to be passed the same $data
array as the EditAction
.
Can anyone think of a different way to go about accomplishing this?
Working:
Nothing passed:
Solution:Jump to solution
dose the delete actually happen only in sushi or you need to call an api?
I would create another action and not using the defualt DeleteAction and debug from there...
15 Replies
Solution
dose the delete actually happen only in sushi or you need to call an api?
I would create another action and not using the defualt DeleteAction and debug from there
the delete can happen anywhere really I was just keeping it in the model under a custom method
you mentioned "model is a remote API", so your model is not holding any actuall data right?
right
it just queries a remote API and returns a mock model of it
pretty much how this is setup: https://filamentphp.com/community/how-to-consume-an-external-api-with-filament-tables
Filament
How to consume an external API with Filament Tables by Leandro Ferr...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
so that is why dont use the DeleteAction since it will call ->delete() on the model
use another action call it (remote delete) and you can call the needed method after or before
I can try a custom action, was trying to find docs where you make those actually
there is action for table,form,infolist etc make sure to use the correct one
Haven't made one of these before, how do you go about passing the data from the model to the action when you edit/delete?
$data I believe is just the modal form, so that would likely work on edit but I need to pass an ID of what's being deleted so that I can process it
$record ?
yeah that works, make sense. Was trying to find it on https://filamentphp.com/docs/3.x/actions/advanced
Awesome! almost there. The record gets deleted, now I need to tell filament that the action was successful I think. Nothing happens on the GUI end after the progress spinner shows up
look in the notification docs, this is the easiest part π
yeah wasn't sure that was the correct way, added a notification in the action
now need to refresh the data as the last step I think
ah looks like it does it now after notification, it didn't before that was added
sweet, thanks for all the help!