[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;