How to Delete uploaded file in Laravel
The public_path function returns the fully qualified path to the public directory and the base_path function returns the fully qualified path to the project root.
So if you want to reach a file in public folder you can use public_path() like this:
You can also use File:delete instead of unlink like this:
use File; File::delete(public_path("test.txt")); // Delete multiple files File::delete($file1, $file2, $file3); // Delete an array of files $files = array($file1, $file2); File::delete($files);
Example with storage:
- Using the default local storage you need to specify public subfolder:
- Use public storage directly: