首页 > 解决方案 > 无法从存储 laravel 中删除图像

问题描述

大家好,我正在尝试使用此功能从本地存储中删除图像,但它返回

调用字符串上的成员函数 delete()

这是正确的,因为当我使用dd(destination);它时,结果是:

public/imagen/1634302328.jpg     

有没有办法将该字符串转换为路由路径或其他解决方案以从存储中删除图像?谢谢

这是我的功能:

public function destroy($id)
    {   
 
        $autoridad = Autoridad::find($id);
        $destination = 'public/imagen/'.$autoridad->imagen;
        if(File::exists($destination)){
            File::delete($destination);
        }
        $destination->delete();
        return redirect()->route('autoridades.index');
    }
    
}

标签: phplaravelroutesdelete-filepublic-method

解决方案


我想你的意思是$autoridad->delete()而不是$destination->delete(). 您分配$destination给图像的字符串位置。这就是为什么它不允许你调用delete()它。


推荐阅读