[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;
After 20 years of transforming global communication, Skype has officially ceased operations. Microsoft, which purchased…
In a serene forest by the edge of a sparkling lake, there lived a cheerful…
Retiring comfortably is a goal many aspire to achieve, and with the right strategies, it’s…
Is your computer running frustratingly slow? Don't worry; you're not alone in facing this common…