FileUpload

First of all, thank you for the awesome job you've done with this framework. I have a form with a FileUpload control, I would like to delete the stored file once it is deleted from this control, What can I do to resolve this?
Solution:
Might be better in an observer though in case you need to reuse it. Let the model delete its files instead of the form.
Jump to solution
4 Replies
WashingtonG
WashingtonGOP8mo ago
Don't tell me it can be solved with this: protected function getActions(): array { return [ Actions\DeleteAction::make() ->after(function (YourModel $record) { // delete single if ($record->photo) { Storage::disk('public')->delete($record->photo); } // delete multiple if ($record->galery) { foreach ($record->galery as $ph) Storage::disk('public')->delete($ph); } }), ]; }
awcodes
awcodes8mo ago
Yep, that should work.
Solution
awcodes
awcodes8mo ago
Might be better in an observer though in case you need to reuse it. Let the model delete its files instead of the form.
WashingtonG
WashingtonGOP8mo ago
Yup, your alternative also seems to have better performance.

Did you find this page helpful?