Im doing my first CRUD(Vue-Laravel) and im getting an error in the backend.
My Laravel.Log:
[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]
My backend:
public function destroy($id) { $despesa = Despesa::find($id); $despesa->delete(); return response()->json('Delete Sucessful'); }
My frontend:
async deleteDespesa(id) { const response = await axios.delete("api/despesas/{despesa}").then((response) => { this.despesas.splice(this.despesas.indexOf(id), 1); this.getDespesa(); });
Advertisement
Answer
If you have a look at your front-end, you’ll see that you don’t specify an ID you want to delete.
You can fix that by replacing
await axios.delete("api/despesas/{despesa}").then((response) => {});
with
const response = await axios.delete("api/despesas/"+id).then((response) => {});