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

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…

2 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…

3 months ago

10 Smart Strategies for a Secure and Enjoyable Retirement

Retiring comfortably is a goal many aspire to achieve, and with the right strategies, it’s…

3 months ago

Troubleshooting a Slow Computer

Is your computer running frustratingly slow? Don't worry; you're not alone in facing this common…

3 months ago

The Clever Fox and the Greedy Crow

Once, in a sunny forest, Fox and Crow were friends. One day, Crow found a…

3 months ago