Q:

Laravel cant add quantity using increment method with modal and ajax

Im making an inventory system with laravel and I want to add a quantity in my product after I registered it, unfortunately I cant update or add the quantity using the increment method in laravel. Also, Im using a modal and ajax in storing the values. Can someone know what is the problem with my codes?
Error code

Controller

  public function stockIn(Request $request, $id){

        $product = Product::findOrFail($id);
        $data = $request->all();

        $product['quantity'] = ($data->increment(['quantity']));

        $product->save();

        return response()->json($data);

    }

Modal

                             {{-- add qty --}}
            <div class="modal fade" id="exampleModalCenter_qty" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered" role="document">
                      <div class="modal-content">
                        <div class="modal-header">
                          <h5 class="modal-title" id="exampleModalCenterTitle">Edit Product</h5>
                          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                          </button>
                        </div>
                        <div class="modal-body">
                        <p style="font-weight: bold;">Enter Quantity </p>
                          <input    type="text" class="form-control" id="add_quantity"/>
                        <div class="modal-footer">
                          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                          <button type="button" class="btn btn-success" id="stockIn">Update</button>
                        </div>
                      </div>
                    </div>
                  </div>
                {{-- add qty --}}

ajax script
  $('.addQty').on('click', function(e) {
                const myValue = $(this).attr('id');
                let qty = $(this).closest('tr').find('td:eq(5)').text();

                $('#add_quantity').val(qty);

                 $('#stockIn').click(function(e) {
                    e.preventDefault();

                    let quantity = $('#add_quantity').val();

                    $.ajaxSetup({
                    headers:{
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        }
                    });

                    $.ajax({
                        url: "{{ url('/addStocks') }}" + '/'+ myValue,
                        method: 'put',
                        data: {
                            name: quantity
                        },
                        success: function(res){
                            console.log(res);
                             window.location.href='{{route("product.index")}}';
                        }
                    })

                 });
              });

route
//addQty
Route::put('/addStocks', 'ProductsController@stockIn');

A:

You need to call ->increment() on the Model, not the Request. Also, your naming is a bit odd with the request value being passed as name.
You might consider changing the name of the data property to quantity.
data: {
    quantity: quantity
},

Update to call ->increment() on the Model.
$product->increment('quantity', request('quantity'));

