hjortur17
697
32
Laravel

Delete function not working

Posted 1 year ago by hjortur17

Hi, I'm trying to delete thread with onClick function. But I get MethodNotAllowedHttpException error

My code is:

<a class="is-trash" onclick="document.getElementById('deleteForm').submit();">
    <i class="fal fa-trash"></i>
</a>
<form method="POST" action="{{ route('thread.delete', $thread) }}" id="deleteForm">
    @csrf
    @method('DELETE')
</form>

And the controller looks like this:

public function destroy(Thread $thread)
{
    $thread->delete();
    return back();
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.