0

i have a problem with my vue component when i'm trying to update a product it returns an error put method is not supported... But it should be supported.

my EditProduct.vue

<form @submit.prevent="submitForm">
   <div class="form-group row">
     <label for="name" class="col-md-4 col-form-label text-md-right">Name:</label>
     <input type="text" name="name" id="name" v-model="product.name">
   </div>
   <div class="form-group row">
     <label class="col-md-4 col-form-label text-md-right">Description:</label>
     <textarea name="description" cols="20" rows="5" v-model="product.description"></textarea>
   </div>
   <div style="display: flex; justify-content: center">
     <button type="submit">Save</button>
   </div>
</form>

my submit method: (i tried patch/put insted of axios.post but it still doesnt work)

    submitForm(){
        let data = new FormData();
        data.append('_method', 'PUT');
        data.append('id', this.product.id);
        data.append('name', this.product.name);
        data.append('description', this.product.description);
        axios.post('edit', data)
        .then( (response) => {
            console.log("success");
        })
    }

my api route:

Route::put('/edit', [ProductController::class, 'update']);

what am i doing wrong here?

1 Answer 1

1

just as I posted the question I realized the url for axios is wrong it should've been

/api/edit

it works now :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.