Reputation: 2763
I have this function to delete image when the row is deleted
public function destroy($id)
{
$slider = Slider::find($id);
$fileName = $slider->image;
$fullPath = asset('/images/banner/' . $fileName);
//dd($fullPath);
File::delete($fullPath);
$slider->delete();
return Redirect::to('admin/home-slider');
}
but sill returned without the file delete. what I did wrong here?
Update
for other who may face the same problem
in my case I deleted the public
from my project before to clean my URL based on this tutorial
Solved by just removing the asset
from the $fullPath
and left it just like that $fullPath = 'images/banner/' . $fileName;
and it's working just fine now
Upvotes: 1
Views: 121
Reputation: 8078
Use base_path()
instead of asset
public function destroy($id)
{
$slider = Slider::find($id);
$fileName = $slider->image;
$fullPath = base_path().'/public/images/banner/'. $fileName;
//dd($fullPath);
File::delete($fullPath);
$slider->delete();
return Redirect::to('admin/home-slider');
}
updated
you can add all images inside the public folder
Upvotes: 1