Mutate form data before create but for delete
I use the above code to update the inventory when inventory is issued out, I was wondering if there is a function like this but for the delete button so I can undo the inventory update if a record from issued inventory is deleted.
8 Replies
I'm pretty sure there is not such a method, because Filament simply passes through the
$record->delete()
to the Model directly.
https://github.com/filamentphp/filament/blob/751c24beb998e334803701ed48a379031256fbaf/packages/actions/src/DeleteAction.php#L48-L58GitHub
filament/packages/actions/src/DeleteAction.php at 751c24beb998e3348...
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
So you probably have two options:
a. clone that DeleteAction and add your own custom logic before the actual delete.
b. fire an Observer or register a
static::deleting
event on the Model, to do your inventory reversalLaravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
what about the
after()
and before()
methods that's available on the delete action ?
https://filamentphp.com/docs/3.x/actions/prebuilt-actions/delete#lifecycle-hooksis it possible for that function to get the data of the record about to be be deleted, like the
$data
array for mutateFormDataBeforeCreate()
Yes that would make sense. Most of the time in Filament you can use
fn (Model $record)
to get the current record. That's not listed on the Actions page in the docs https://filamentphp.com/docs/3.x/actions/advanced ... but it is in the Table docs. https://filamentphp.com/docs/3.x/tables/actions#table-action-utility-injectionSolution
Yup That works, Thank You.
Here's the code if anyone else is interested
Excellent!
(please also mark that post as "the answer": right-click it, choose "Apps" and "Mark Selected")