How to delete the image from the storage in laravel?

Member

by mac , in category: PHP Frameworks , a year ago

How to delete the image from the storage in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by larissa , 10 months ago

@mac 

To delete an image from storage in Laravel, you can use the Storage facade to delete the file. Here's an example of how you can delete an image from the storage:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
use IlluminateSupportFacadesStorage;

$path = 'path/to/your/image.jpg';

if (Storage::exists($path)) {
    Storage::delete($path);
    // File deleted successfully
} else {
    // File does not exist
}


In this example, we first check if the file exists in storage using the exists method of the Storage facade. If the file exists, we then use the delete method to delete the file from storage.


Make sure to replace 'path/to/your/image.jpg' with the actual path to your image file.

Related Threads:

How to display storage image in laravel blade?
How to delete image with ajax in laravel?
How to play a video from storage in laravel?
How to mock storage file download in laravel?
How to access storage file from .env file in laravel?
How delete file and image after upload from codeigniter??