If you want to delete an image from your server, you have to reference the location of file in directory server, which means you could not reference by URL link to delete it.
Commonly, Laravel 5 file is located in public folder.
For example: your files are located in public/images
$image_path = "/images/filename.ext"; // Value is not URL but directory file path
if(File::exists($image_path)) {
File::delete($image_path);
}
The example above works only a single file. For deleted multiple files you can use by following overload parameter:
File::delete($file1, $file2, $file3);
//Or put in array
$files = array($file1, $file2);
File::delete($files);
File
we have to insert a statement on the top of the Controller
file you have to import that class by following:
use Illuminate\Support\Facades\File;
This was test on Laravel 5 and working properly.
Reference: here
LaravelAs the founder and passionate educator behind this platform, I’m dedicated to sharing practical knowledge in programming to help you grow. Whether you’re a beginner exploring Machine Learning, PHP, Laravel, Python, Java, or Android Development, you’ll find tutorials here that are simple, accessible, and easy to understand. My mission is to make learning enjoyable and effective for everyone. Dive in, start learning, and don’t forget to follow along for more tips and insights!. Follow him