php - Crud Destroy不是破坏
问题描述
我在做我的第一个 CRUD(Vue-Laravel)并且我在后端遇到错误。
我的 Laravel 日志:
[2020-11-29 00:13:31] local.ERROR: Call to a member function delete() on null {"exception":"[object] (Error(code: 0): Call to a member function delete() on null at C:\\Users\\DEUS GUILHERME\\Documents\\GitHub\\dadus-financeiro-backend\\app\\Http\\Controllers\\DespesaController.php:49)
[stacktrace]
我的后端:
public function destroy($id)
{
$despesa = Despesa::find($id);
$despesa->delete();
return response()->json('Delete Sucessful');
}
我的前端:
async deleteDespesa(id) {
const response = await axios.delete("api/despesas/{despesa}").then((response) => {
this.despesas.splice(this.despesas.indexOf(id), 1);
this.getDespesa();
});
解决方案
如果您查看前端,您会发现您没有指定要删除的 ID。
你可以通过更换来解决这个问题
await axios.delete("api/despesas/{despesa}").then((response) => {});
和
const response = await axios.delete("api/despesas/"+id).then((response) => {});
推荐阅读
- java - 如何为 @Sql 指定数据源以进行 Spring 测试
- java - 在java中使用文本文件查找集合和类的平均值
- javascript - 加载后链接文档中的任意文本
- excel - 如何在 WinHTTP VBA 中禁用 SSL 证书验证 - 自动化错误
- python - 编译 discord.py 时如何解决错误?
- reactjs - 如何在 nextjs 中使用 React 组件?
- oracle12.1 - 如何使用另一个参考游标变量分配一个参考游标?
- python - 列表到 csv-python
- google-cloud-platform - ansible:gcp_compute_disk - 从快照创建磁盘的问题
- variables - 变量名和逗号后的下划线有什么作用?