How to delete file from public folder in laravel 5.1

后端 未结 17 1643
悲哀的现实
悲哀的现实 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:26

    public function destroy($id) {
        $news = News::findOrFail($id);
        $image_path = app_path("images/news/".$news->photo);
    
        if(file_exists($image_path)){
            //File::delete($image_path);
            File::delete( $image_path);
        }
        $news->delete();
        return redirect('admin/dashboard')->with('message','خبر موفقانه حذف  شد');
    }
    

提交回复
热议问题