php - 无法从存储 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');
}
}
解决方案
我想你的意思是$autoridad->delete()
而不是$destination->delete()
. 您分配$destination
给图像的字符串位置。这就是为什么它不允许你调用delete()
它。
推荐阅读
- sql - postgresql中不同产品的打开和关闭数量查询
- python-3.x - 当我以普通用户身份使用 virtulenv 时 pip3 安装错误
- docker - 如何验证分配给 docker 容器的 cpu 限制?
- mongodb - MongoDB安装错误-INSTALL_FAILED-dbpath (C:\mongodata) 不存在
- android - 单击其中的项目时停留在导航抽屉中
- firebase - 反应原生 Firebase 身份验证
- python - 来自 Windows 客户端的 IPv6 服务器的 Paramiko ssh exec_command
- java - 如何修复java2smali中android studio的错误
- python - Selenium Python - 如果元素存在转到列表中的下一项
- android - 需要帮助弄清楚如何使用 api 密钥比较用户输入和从网站提取数据