[Vuejs]-Http request 500 internal server error on Axios put

0👍

You don’t need to create another instance of the Sales object after finding it:

public function update(Request $req, $id){
    $sales = Sales::find($id);
    $sales->itemQty = $req['itemQty'];
    $sales->itemID = $req['itemID'];
    $sales->save();
}

I don’t think your intention is to have your data submitted in array. So remove [] from the input field names:

<div class="card-body"  v-for="(sale, index) in sales" :key="sale.id">
          <form action="/Sales" method="post">
              <div>
                <input type="hidden" name="_token" :value="csrf">
                  <div class="form-group">

                    <div class="form-inline">
                      <div class="mr-3 mt-2">Item ID: </div>
                      <input class="form-control mt-2 col" name="itemID" maxlength="12" v-model="sale.itemID">
                    </div>

                    <div class="form-inline">
                      <div class="mr-2 mt-2">Quantity: </div>
                      <input type="number" min="1" class="form-control mt-2 col" placeholder="Quantity" name="itemQty" v-model="sale.itemQty">
                    </div>

                  </div>
              </div>
              <div class="updatesale" style="margin:0 auto; text-align: center;">
                <button class="btn btn-success mt-2" type="button" name="button" v-on:click="updateSalesRec(sale.id)">Update</button>
              </div>
          </form>
        </div>

Hope this is useful.

Leave a comment