How to delete file(s) in Laravel 5

Deleting files from the file system is very common task nowadays and it can be done in several ways. But here I am gonna show you deleting files in the Laravel way.

We generally use PHP’s built-in unlink() function to delete files from the file system, there is nothing wrong using it. But we gonna use Laravel’s File::delete() method because it is giving the option to delete multiple files at once.

Note: If there is a problem with deleting a file, the error is silently ignored, so it is always better to check the existence of the file with File::exists().

Delete single file

Delete Multiple file

Delete an array of files

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

Leave a Reply

Your email address will not be published. Required fields are marked *