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

ruben777's avatar

405 error when deleting row

I am working with Laravel and Inertia+Vue.js.

I am trying to delete a row but I get a 405 error method not allowed.

Here is my code in Layout.vue :

<a @click="destroy(website)">delete</a>
import AppLayout from '@/Layouts/AppLayout.vue';
import {Link} from "@inertiajs/inertia-vue3";
import {Inertia} from "@inertiajs/inertia";

export default {
    components: {
        Link, AppLayout, Inertia
    },

    props: {
        websites: Object
    },

    methods: {
        destroy(website) {
            if(confirm('are u sure?')) {
                this.$inertia.delete(`/destroy/website/${website.id}`)
            }
        }
    },

the method in my controller :

public function destroy(Website $website)
    {
       $website->delete();
       return redirect()->route('dashboard');
    }

and my route in web.php :

Route::delete('/destroy/website/{id}', [WebsiteController::class, 'destroy']);

any help will be much appreciated !

0 likes
13 replies
splatEric's avatar

405 indicates that method is not supported on that URL ... I would inspect the network to see what request you are actually making from the browser, and run artisan route:list to verify that your route has been defined correctly.

Bear in mind that the delete method is spoofed by laravel by posting an additional form variable with a POST request.

MohamedTammam's avatar

@ruben777 What's the result of

public function destroy(Website $website)
    {
		dd('here'); // Does it get here?
       $website->delete();
       return redirect()->route('dashboard');
    }

ruben777's avatar

@MohamedTammam it does get here. the answer was to set the route like this :

Route::delete('/destroy/website/{website}', [WebsiteController::class, 'destroy']);

thank you for your time !

1 like
tykus's avatar

You are using a link (a tag) but not preventing the default behaviour

<a @click.prevent="destroy(website)">delete</a>

Or better; use a button instead:

<button @click="destroy(website)">delete</button>

Of course, since this is Inertia, you could instead use the Link component - although the caveat about using an anchor tag still applies!!!

jorshhh's avatar

@tykus Just signed up to say thank you! This was my problem, I was using a button with a click function inside a <Link> tag and it was messing everything up

ruben777's avatar

the answer was to set the route like this :

Route::delete('/destroy/website/{website}', [WebsiteController::class, 'destroy']);

thank you all for your time !

ruben777's avatar

@tykus the thing is that I work in a root directory /app so my URL always looks something like this : website.fr/app/page.

I have no right to access what is not in app/ directory and my first request was outside that directory. giving {website} instead of {id} is passing the whole model to the back-end and. In other words, my first request was like this : website.fr/destroy/website/id, now it looks the good way, website.fr/app/destroy/website/id

tykus's avatar

@ruben777 so there was a redirect - that would result in a 405 🤷‍♂️

ruben777's avatar

@tykus yes I also used a button just as you said but this answer did not work alone

Please or to participate in this conversation.