How to delete file in Laravel 6 ?

Laravel 6 , Laravel

Nicesnippets

373

26-09-2019


hi guys,

In this example, i will show you laravel 6 remove file from folder using File object. we can easily delete file in laravel 6. we can solved simply define the command then delete the file in laravel 6.

you are just trying to use File::delete to delete file from public path, but always i got the message "File not found at path".

solution for laravel

/**

* Show the application dashboard.

*

* @return \Illuminate\Contracts\Support\Renderable

*/

public function index(Request $request)

{

$file = public_path('img/slider.jpeg');

$img = File::delete($file);

dd($img);

}

If return true this method success, return false this method fails.

solution for core php

/**

* Show the application dashboard.

*

* @return \Illuminate\Contracts\Support\Renderable

*/

public function index(Request $request)

{

$file = public_path('img/slider.jpeg');

$img = unlink($file);

dd($img);

}

If return true this method success, return false this method fails.

It will help you...