How to Delete image from storage in laravel?

public function delete_category(Request $request,$id='')
{
//DB::table('Categorys')->where('id',$id)->delete();
//$id = $request->get('id');
//$deletedRows = Category::where('id', $id)->delete();
//return redirect('showcategory');

$id = $request->get('id');
$data = Category::findOrFail($id);
$image_path = storage_path().'/category_image/'.$data->category_image;
unlink($image_path);
$data->delete();
// if(Storage::delete($data->category_image)) {
// $data->delete();
// }

return response()->json(['success'=>"Product Deleted successfully."]);
exit;
}

Using File System:

public function removeImage()

{

if(\File::exists(public_path('upload/itechxpert.png'))){

\File::delete(public_path('upload/itechxpert.png'));

}else{

dd('File does not exists.');

}

}

Using Storage System

File name : index.php

public function removeImage()

{

if(\Storage::exists('upload/itechxpert.png')){

\Storage::delete('upload/itechxpert.png');

}else{

dd('File does not exists.');

}

}

Using Core PHP:

public function removeImage()

{

if(file_exists(public_path('upload/itechxpert.png'))){

unlink(public_path('upload/itechxpert.png'));

}else{

dd('File does not exists.');

}

}





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here


Ittutorial