F
Filament15mo ago
hxn

Uploaded image not deleted on delete

When deleting a record the image in storage isnt deleted. I've tried something like this but record is protected
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make()
->after(function ($action){
unlink(storage_path('app/public/'. $action->record->image_url));
}),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make()
->after(function ($action){
unlink(storage_path('app/public/'. $action->record->image_url));
}),
])
8 Replies
Dennis Koch
Dennis Koch15mo ago
Yes that’s intended and mentioned in the docs. I think you can access $this->record
hxn
hxn15mo ago
Thanks for your reply
Using $this when not in object context
Using $this when not in object context
Dennis Koch
Dennis Koch15mo ago
BTW after might be to late since the record is already deleted I’d use an observer or model event
hxn
hxn15mo ago
thanks, I will probably make an observer if there is no other option in filament
tuseto
tuseto5mo ago
How I can delete image which is uploaded via RichText Editor ?
awcodes
awcodes5mo ago
You’d have to parse the content for any images, collect them in an array then delete them. But an observer would still be the best place to do it.
tuseto
tuseto4mo ago
What do you think, what is the proper solution of image is inserted in the editor, but the resource is not updated, so the observer is not fired, but the image is uploaded immediately when inserted in the editor no matter if the resource is saved/updated or not.
awcodes
awcodes4mo ago
Honestly I think you’re worrying about things that don’t truly matter. Like oh no, there’s unused images on the server that aren’t getting severed. If that actually matters then you need to look into using one of the media manager plugins. Or create your own media management solution.