I think you're after the public_path() instead.
// Note removal of app_path()
$image_path = public_path().'/images/news/'.$news->photo;
I trying to delete a News from news table and it has an image field and the image is located in images/news directory in public folder after uploading, but the image itself is not deleted from that folder and only its path is deleted from database. any help the function:
public function destroy($id)
{
$news = News::findOrFail($id);
$image_path = app_path().'/images/news/'.$news->photo;
//dd($image_path);
if(File::exists($image_path))
{
File::delete($image_path);
//unlink($image_path);
}
$news->delete();
return redirect('admin/dashboard')->with('message','خبر موفقانه حذف شد');
}
Yes, I solved by changing like so:
public function destroy($id)
{
$news = News::findOrFail($id);
$image_path = public_path().'/'.$news->photo;
unlink($image_path);
$news->delete();
return redirect('admin/dashboard')->with('message','خبر موفقانه حذف شد');
}
Thanks all for taking your time to reply.
Please or to participate in this conversation.