How to delete file from public folder in laravel 5.1

Solution 1:

You could use PHP's unlink() method just as @Khan suggested.

But if you want to do it the Laravel way, use the File::delete() method instead.

// Delete a single file

File::delete($filename);

// Delete multiple files

File::delete($file1, $file2, $file3);

// Delete an array of files

$files = array($file1, $file2);
File::delete($files);

And don't forget to add at the top:

use Illuminate\Support\Facades\File; 

Solution 2:

Use the unlink function of php, just pass exact path to your file to unlink function :

unlink($file_path);

Do not forget to create complete path of your file if it is not stored in the DB. e.g

$file_path = app_path().'/images/news/'.$news->photo;

Solution 3:

this method worked for me
First, put the line below at the beginning of your controller:

use File;

below namespace in your php file Second:

 $destinationPath = 'your_path';
 File::delete($destinationPath.'/your_file');

$destinationPath --> the folder inside folder public.