首页 > 解决方案 > 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();
  });

标签: phplaravel

解决方案


如果您查看前端,您会发现您没有指定要删除的 ID。

你可以通过更换来解决这个问题

await axios.delete("api/despesas/{despesa}").then((response) => {});

const response = await axios.delete("api/despesas/"+id).then((response) => {});


推荐阅读