i have a laravel project and i want to delete image from this directory
myLaravelProject/public/images/banners
Storage::disk('public')->delete("images/banners/{$image_name}");
i have a laravel project and i want to delete image from this directory
myLaravelProject/public/images/banners
Storage::disk('public')->delete("images/banners/{$image_name}");
For good practice you need to edit config with a new storage disc in config/filesystems.php
:
'public_uploads' => [
'driver' => 'local',
'root' => public_path() . '/images/banners/',
]
and then
Storage::disk('public_uploads')->delete("{$image_name}");
Something like this works for me:
use File;
$file_path = public_path(substr($this->path, 1));
if(File::exists($file_path)) {
File::delete($file_path);
}
For Laravel 8, this code works for me:
use Illuminate\Support\Facades\File;
$file_path = public_path('upload/test.png');
if(File::exists($file_path)) {
File::delete($file_path);
}
I hope it helps!