Categories: Laravel

Cant Delete File in Laravel? [SOLUTION]

[Q] I am using laravel and while deleting a file in laravel It got error while code is live but worked fine in localhost.
Error Looked like this

controller is as follow

public function destroy($id)
{


$del=Slider::find($id);

if (!empty($del->image)) {
$image_path = public_path("images/slider/{$del->image}");
//File::delete($image_path);
unlink($image_path);
}

$chk=$del->delete();


if($chk){

$data=Slider::get();

Session()->flash('msg','A Slider has been deleted.');

return view('backend.slider',compact('data'));

}


}

 

[SOLUTION]
Instead of using unlik() I used File::delete()
so

unlink($image_path);

 

above code I replaced with

File::delete($image_path);

 

And Dont forget to add this to the top of the controller

use Illuminate\Support\Facades\File;

 

jaminrai

Share
Published by
jaminrai

Recent Posts

Computer Science Project Report Guidelines and Sample

Guidelines (Click Below to Download) SAMPLE 1 SAMPLE 2

4 months ago

Skype Closes Its Doors After 20 Years: A Look Back and the Apps That Faded with It

After 20 years of transforming global communication, Skype has officially ceased operations. Microsoft, which purchased…

11 months ago

The Duck and the Tortoise: A Tale of Patience and Teamwork

In a serene forest by the edge of a sparkling lake, there lived a cheerful…

12 months ago