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?

iSnuff
  • 285
  • 1
  • 3
  • 14

1 Answers1

1

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

/api/edit

it works now :)

iSnuff
  • 285
  • 1
  • 3
  • 14