How to delete file from public folder in laravel 5.1

后端 未结 17 1719
悲哀的现实
悲哀的现实 2020-11-30 09:02

I want to delete a News from database and when I hit the delete button all data from database deleted but the image is remains in upload folder. So, how do I this to work. t

17条回答
  •  甜味超标
    2020-11-30 09:37

    First make sure the file exist by building the path

    if($request->hasFile('image')){
        $path = storage_path().'/app/public/YOUR_FOLDER/'.$db->image;
          if(File::exists($path)){
              unlink($path);
          }
    

提交回复
热议问题