[Files-Module] - How can you force delete a file (skip trash and remove the resource)

edster - 3 weeks ago

I have been trying to figure out how to delete a file from files module and resource, I know I can delete the file with Storage:: but I know there is a way to do it from the files module.

Answer

piterden - 3 weeks ago

Storage:: is the bad practice. Use repositories FileRepositoryInterface $files->forceDelete()

piterden - 3 weeks ago

Storage:: is the bad practice. Use repositories FileRepositoryInterface $files->forceDelete()

edster - 3 weeks ago

Ah you do it through the repository, thanks @piterden!

ryanthompson - 2 weeks ago

@edster you can technically do it with the model as well.

edster - 2 weeks ago

Thanks @ryanthompson, so do $model->forceDelete() and that does the same?

What if I want to do this from a related stream/model.

I have a documents stream with a related file, (1-1) when I delete the document record, I want cascade and force delete the resource.