Reputation: 222
i was trying to follow this tutorial on Laravel, even though most of the code & directories there were outdated, i managed to make the "Add Task" and also The Form to show up after a few errors.
now the problem, the delete button. when i click on it, it shows a "MethodNotAllowedHttpException". i changed the source code to match the newest version of Laravel.
my form (current version) :
<form action="{{ url('/task/'.$task->id) }}" method="POST">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger">
<i class="fa fa-btn fa-trash"></i>Delete
</button>
</form>
my route :
Route::delete('/task/{id}', function ($id) {
Task::findOrFail($id)->delete();
return redirect('/');
});
i've been trying to fix this for 4 hours now, changing the methods of my route and form; but to no avail. this is my first question on this site, sorry if there's something wrong in this question.
thanks~
edit: to further help the effort, here's the complete error log Error log, in Google Chrome
Upvotes: 0
Views: 2664
Reputation: 2541
Change
<form action="{{ url('task/'.$task->id) }}" method="DELETE">
to
<form action="{{ url('task/'.$task->id) }}" method="POST">
Because form method DELETE does not exist, Laravel just "overwrites" this method with the hidden input "method" (you can place this input using "{{ method_field('DELETE') }}
").
Upvotes: 4
Reputation: 222
Answer : Turns out the problem lies in the Database-table itself, let me explain : i was referring to a 'tasks' table that is referred as 'task' in code (no problem) BUT, i was referring to a column called "ID" in my table as "id" in my code, creating the error (a rookie mistake).
thanks to @Autista_z for the pointer, and everyone else below for the guidance!
Upvotes: 0
Reputation: 1731
Form dosent support method Delete or Put ... It support only get and post methods, if You want implement delete in laravel this article will help you link
Upvotes: 0