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:
Tables\Actions\EditAction::make()->using(function (Model $record, array $data): Model {
\App\Models\Rule::updateRecordAPI($data);
return $record;
}),
Tables\Actions\EditAction::make()->using(function (Model $record, array $data): Model {
\App\Models\Rule::updateRecordAPI($data);
return $record;
}),
Nothing passed:
Tables\Actions\DeleteAction::make()->after(function (array $data){
dd($data);
})
Tables\Actions\DeleteAction::make()->after(function (array $data){
dd($data);
})
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...
Jump to solution
15 Replies
Solution
Lara Zeus
Lara Zeusβ€’6mo ago
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
pepperoni dogfart
pepperoni dogfartβ€’6mo ago
the delete can happen anywhere really I was just keeping it in the model under a custom method
Lara Zeus
Lara Zeusβ€’6mo ago
you mentioned "model is a remote API", so your model is not holding any actuall data right?
pepperoni dogfart
pepperoni dogfartβ€’6mo ago
right it just queries a remote API and returns a mock model of it
pepperoni dogfart
pepperoni dogfartβ€’6mo ago
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.
Lara Zeus
Lara Zeusβ€’6mo ago
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
pepperoni dogfart
pepperoni dogfartβ€’6mo ago
I can try a custom action, was trying to find docs where you make those actually
Lara Zeus
Lara Zeusβ€’6mo ago
there is action for table,form,infolist etc make sure to use the correct one
pepperoni dogfart
pepperoni dogfartβ€’6mo ago
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?
Tables\Actions\Action::make('RemoteDelete')
->label('Delete')
->color('danger')
->action(function (array $data) {
dd($data);
})
Tables\Actions\Action::make('RemoteDelete')
->label('Delete')
->color('danger')
->action(function (array $data) {
dd($data);
})
$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
Lara Zeus
Lara Zeusβ€’6mo ago
$record ?
pepperoni dogfart
pepperoni dogfartβ€’6mo ago
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
Lara Zeus
Lara Zeusβ€’6mo ago
look in the notification docs, this is the easiest part πŸ™‚
pepperoni dogfart
pepperoni dogfartβ€’6mo ago
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!