Delete function not working

Posted 8 months 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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.