Reputation: 443
I've got the error "The DELETE method is not supported for this route. Supported methods: GET, HEAD, POST." when I want to delete some item in my database base on their's Id. Here is my code :
index.blade.php
<form action="{{ $note->id }}" method="post" class="d-inline">
@csrf
@method('DELETE')
<button type="submit"
class="bg-red-500 text-white font-bold px-4 py-2 text-sm uppercase rounded tracking-wider focus:outline-none hover:bg-pink-400">
Delete</button>
</form>
web.php
Route::group(['middleware' => 'auth'], function () {
Route::resource('notes', NoteController::class);
});
NoteController.php
public function destroy(Note $note_id)
{
//
$userId = Auth::user()->id;
Note::where(['user_id' => $userId, 'note_id' => $note_id])->delete();
return $note_id;
}
How can I fix this error so I can delete my item from my database? Thank You :)
Upvotes: 0
Views: 848
Reputation: 1296
you need to change the action param to action="/notes/{{$note->id}}"
you are not hitting that route . you are hitting /{id}
or use named routes action="{{ route('notes.destroy', $note->id ) }}
since you are using resource will make named routes for store show destroy and update all prefixed with name notes.
so if you need the destroy route you have to access /notes/id named notes.destroy
you can use php artisan route:list
to see all of your registered routes with their names and uris
Upvotes: 3