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

eggplantSword's avatar

PUT or DELETE method not allowed, only GET HEAD POST

This has happened to me on another project and I just gave up and made everything a post. I want to find out why this is happening. I'm using Vue and Inertia.js. In this case I'm trying to update but the same happens for the delete route. I'm using Laravel 8 in case that is relevant.

The bizarre thing is I get the error but after reloading the item have been successfully edited or deleted, I don't understand the error if it's just gonna do it anyway.

This is my code for the update and delete inertia requests

baseUrl: '/category';

//update
 this.$inertia.put(this.baseUrl + '/' + this.form.id, this.form);

//delete
this.$inertia.delete(this.baseUrl + '/' + $id);

the routes

Route::resource('category', 'CategoryController')->except(['create', 'edit']);

the methods in my controller

public function update(Request $request, $id)
    {
        $request->validate([
            'name' => 'required|max:255|unique:categories,name,' . $id,
            'description' => 'required|max:255',
        ]);

        $category = Category::findOrFail($id);
        $category->name = $request->name;
        $category->description = $request->description;
        $category->save();
        DB::commit();

        return back();
    }

public function destroy($id)
    {
        DB::beginTransaction();
        $category = Category::findOrFail($id);
        $category->delete();
        DB::commit();
        return redirect('/category');
    }

I have both a redirect and just a return back to see if that was causing the issue but it's not.

Also in the networking tab on my browser I can see it has made 2 requests one is to the correct url

Request URL:http://me.massiels/category/3
Request Method: PUT 
Status Code: 302 Found 

and another one that is the one giving me an error

Request URL: http://me.massiels/category
Request Method: PUT 
Status Code: 405 Method Not Allowed

I ran route:cache, route:clear, composer dumpautoload, and route:list the list appears like this

GET|HEAD|category|category.index|CategoryController@index|web|auth|role:admin 

POST|category|category.store|CategoryController@store|web|auth|role:admin 

DELETE|category/{category}|category.destroy|CategoryController@destroy|web |auth|role:admin

PUT|PATCH|category/{category}|category.update|CategoryController@update|web|auth|role:admin

GET|HEAD|category/{category}|category.show|CategoryController@show |web|auth|role:admin

What am I doing wrong, how can I fix this?

0 likes
12 replies
mabdullahsari's avatar

You are not passing the category ID when trying to update the resource, look carefully:

Request URL: http://me.massiels/category
eggplantSword's avatar

I am, it's doing 2 requests for some reason, the first one has the correct url / parameter but returns a 302 and the second one doesn't have the correct parameter or url.

mabdullahsari's avatar

OK, my bad, misread the HTTP verb in the first request. Can you try replacing back() with redirect()->route('category.index')

1 like
eggplantSword's avatar

Same result, I did do a dd('return') instead of the return and I don't get the error. It has to be the return messing this up somehow.

eggplantSword's avatar

I'm using https://element.eleme.io/#/en-US/component/form for my form, in their docs it doesn't say I have to do that. I've never had to before. This is my form code

<el-form :model="form" ref="form" :rules="rules" status-icon>
    <el-form-item label="Nombre" prop="name">
        <el-input placeholder="Nombre" v-model="form.name"></el-input>
    </el-form-item>

    <el-button @click="submit()">Guardar</el-button>
</el-form>


//submit method
submit() {
    this.$refs.form.validate(() => {
        this.loading = true;

        if (!this.form.id) {
            this.$inertia.post(this.baseUrl, this.form);
        } else {
            this.$inertia.put(this.baseUrl + '/' + this.form.id, this.form);
        }
    });
},
jlrdw's avatar

I've never had to before.

Try like you did before.

eggplantSword's avatar

This is the same exact code as before I'm just now getting these errors and I have no clue why.

eggplantSword's avatar

This helped me fix the update. I wasn't sending as FormData at all I was sending the object instead. The delete is still giving me trouble.

jlrdw's avatar

If solved please show as solved to help others who may have encountered the same issue.

Please or to participate in this conversation.