How to delete file from public folder in laravel 5.1

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

    Update working for Laravel 8.x:

    Deleting an image for example ->

    First of all add the File Facade at the top of the controller:

    use Illuminate\Support\Facades\File;
    

    Then use delete function. If the file is in 'public/' you have to specify the path using public_path() function:

    File::delete(public_path("images/filename.png"));
    

提交回复
热议问题