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

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Published by Arjun

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

Leave a comment

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