How to delete file from public folder in laravel 5.1

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

    Two ways to delete the image from public folder without changing laravel filesystems config file or messing with pure php unlink function:

    1. Using the default local storage you need to specify public subfolder:
    Storage::delete('public/'.$image_path);
    
    1. Use public storage directly:
    Storage::disk('public')->delete($image_path);
    

    I would suggest second way as the best one.

    Hope this help other people.

提交回复
热议问题