Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FireBlade's avatar

Laravel Delete Using Fetch API

This request fails with error 405 Method Not Allowed

fetch(`/posts/${id}`, {
            method: 'DELETE',
            headers: { 
                'X-CSRF-TOKEN': document.head.querySelector('meta[name=csrf-token]').content,
            }
        })
        .catch((error) => {
            console.log(error);
        })
        .finally(() => {
            
        });
0 likes
8 replies
vincent15000's avatar

If the method is not allowed, this is probably due to the definition of the route.

Can you show the route please ?

FireBlade's avatar

@vincent15000 The route is surely defined:

route:list

DELETE   posts/{post} ................................. posts.destroy › PostController@destroy

1 like
vincent15000's avatar

@FireBlade Why are you using fetch ? With axios all is done automatically to pass the CSRF token.

Without any further details : code, explanations about what you already have tested, ... and not just words, ... it will be difficult to help you efficiently.

1 like
FireBlade's avatar

@vincent15000 User needs to confirm delete action before app sends request. Am using Livewire + Jetstream. Never tried that option. Ok. Let me check that out

1 like
vincent15000's avatar

@FireBlade Ok that's much more clearer for me now.

I would try to use AlpineJS to manage the confirmation. Livewire and AlpineJS work well together.

Please or to participate in this conversation.