title: Ajax takes wrong product id Laravel
body: <p>I have a Laravel test project and I am trying to update the total cost based on the qty value in input.
  Here is my ajax:</p>
  <pre><code>$(document).ready(function() {
  $('input[name=inputModal]').change(function() {
  let qty = parseInt($('input[name=inputModal]').val());
  let id = $('.card').data('id');
  $.ajax({
  url: '/modal/update/' + id,
  dataType: 'JSON',
  data:{
    qty:qty
  },
  success: function(response) {
  $('.totalPrice').html(response.totalPrice);
  }
  });
  return false;
  });
  });
  </code></pre>
  <p>I was also trying to make a hidden input and take the value from there. But be that as it may, when I change the input value, ajax always accepts ID 4, no matter which ID I choose.</p>
  <p>Route for cost updating:</p>
  <p><code>Route::get('/modal/update/{id}', [BasketController::class, 'modal_order_update'])-&gt;name('modal_order_update');</code></p>
  <p>CartController:</p>
  <pre><code>public function modal_order_update(Request $request, $id){
      $product = Product::find($id);
      $modalQty = $request-&gt;qty;
        return response()-&gt;json([
              'price' =&gt; $product-&gt;price*$modalQty
         ]);
    }
  </code></pre>
  <p>Modal window:</p>
  <pre><code>&lt;!-- Modal --&gt;
  &lt;div class=&quot;modal fade&quot; id=&quot;staticBackdrop&quot; data-backdrop=&quot;static&quot; data-keyboard=&quot;false&quot; tabindex=&quot;-1&quot; aria-labelledby=&quot;staticBackdropLabel&quot; aria-hidden=&quot;true&quot;&gt;
    &lt;div class=&quot;modal-dialog modal-dialog-centered&quot;&gt;
      &lt;div class=&quot;modal-content&quot;&gt;
        &lt;div class=&quot;modal-body&quot;&gt;
          &lt;!-- --&gt;
          &lt;div class=&quot;login-form modal-purchase&quot;&gt;
              &lt;form action=&quot;&quot; method=&quot;POST&quot;&gt;
                &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;
                  &lt;span aria-hidden=&quot;true&quot; class=&quot;close-modal&quot;&gt;&amp;times;&lt;/span&gt;
                &lt;/button&gt;
                @csrf
                    &lt;h2 class=&quot;text-center&quot;&gt;Placing order&lt;/h2&gt;
                    &lt;table class=&quot;table&quot;&gt;
                      &lt;tbody&gt;
                        &lt;tr&gt;
                          &lt;th scope=&quot;row&quot;&gt;&lt;a href=&quot;/&quot;&gt;&lt;img class=&quot;basketimg mr-1&quot; src=&quot;&quot;&gt;&lt;/a&gt;&lt;/th&gt;
                          &lt;td&gt;&lt;span class=&quot;basket-prod-name&quot;&gt;&lt;/span&gt;&lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                          &lt;th scope=&quot;cols&quot;&gt;
                                  &lt;!-- &lt;input type=&quot;hidden&quot; name=&quot;item_price&quot;&gt; --&gt;
                                  &lt;input type=&quot;number&quot; name=&quot;inputModal&quot; min=&quot;1&quot; max=&quot;100&quot;&gt;&lt;/input&gt;
                          &lt;/th&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                          &lt;td colspan=&quot;3&quot;&gt;&lt;h5&gt;Total cost:&lt;/h5&gt;&lt;/td&gt;
                          &lt;td class=&quot;d-flex&quot;&gt;&lt;h5 class=&quot;totalPrice&quot;&gt;&lt;/h5&gt;&lt;h5&gt;AZN&lt;/h5&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;/tbody&gt;
                    &lt;/table&gt;
                  &lt;div class=&quot;form-group&quot;&gt;
                      &lt;input id=&quot;name&quot; type=&quot;text&quot; class=&quot;form-control @error('name') is-invalid @enderror&quot; name=&quot;name&quot; value=&quot;&quot; placeholder=&quot;Enter your name&quot; required autocomplete=&quot;name&quot; autofocus&gt;
  
                      @error('name')
                          &lt;span class=&quot;invalid-feedback&quot; role=&quot;alert&quot;&gt;
                              &lt;strong&gt;&lt;/strong&gt;
                          &lt;/span&gt;
                      @enderror
  
                  &lt;/div&gt;
                   &lt;div class=&quot;form-group&quot;&gt;
                        &lt;input id=&quot;email&quot; type=&quot;email&quot; class=&quot;form-control @error('email') is-invalid @enderror&quot; name=&quot;email&quot; value=&quot;&quot; placeholder=&quot;E-Mail Address&quot; required autocomplete=&quot;email&quot;&gt;
  
                        @error('email')
                            &lt;span class=&quot;invalid-feedback&quot; role=&quot;alert&quot;&gt;
                                &lt;strong&gt;&lt;/strong&gt;
                            &lt;/span&gt;
                        @enderror
  
                   &lt;/div&gt;
                   &lt;div class=&quot;form-group&quot;&gt;
                        &lt;input id=&quot;phone&quot; type=&quot;phone&quot; class=&quot;form-control @error('phone') is-invalid @enderror&quot; name=&quot;phone&quot; placeholder=&quot;phone&quot; required&gt;
  
                        @error('password')
                            &lt;span class=&quot;invalid-feedback&quot; role=&quot;alert&quot;&gt;
                                &lt;strong&gt;&lt;/strong&gt;
                            &lt;/span&gt;
                        @enderror
  
                   &lt;/div&gt;
                   &lt;div class=&quot;form-group&quot;&gt;
                      &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary btn-lg btn-block&quot;&gt;Place order&lt;/button&gt;
                   &lt;/div&gt;
              &lt;/form&gt;
          &lt;/div&gt;
          &lt;!-- --&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/KxtOR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KxtOR.png" alt="Network page" /></a></p>
  <p>A single digit (2,3,4) is the id of the product that the user has selected.
  And for example: 4? Qty = 2 - the user changes the quantity of product. The first digit is id and for some reason it is always 4.</p>
  <pre><code>index.blade.php where modal included with @include directive:
  @section('content')
  @include(inc.flash)
  @include(inc.modal-order)
  &lt;section class=&quot;container&quot;&gt;
      &lt;h1 class=&quot;s2tittle&quot;&gt;Leaders of sells&lt;/h1&gt;
        &lt;div class=&quot;slider&quot;&gt;
          @foreach($proditem as $product)
            @foreach($product-&gt;products as $item)
              &lt;div class=&quot;card&quot;&gt;
                &lt;a href=&quot;/{{ $product-&gt;code }}/{{ $product-&gt;url }}/{{ $item-&gt;url }}&quot;&gt;&lt;img class=&quot;card-img-top&quot; src=&quot;/img/products/{{ $item-&gt;cardImage-&gt;path}}&quot; alt=&quot;Card image cap&quot;&gt;&lt;/a&gt;
                &lt;div class=&quot;card-body&quot;&gt;
                  &lt;a href=&quot;/{{ $product-&gt;code }}/{{ $product-&gt;url }}/{{ $item-&gt;url }}&quot;&gt;&lt;h5 class=&quot;card-title text-center&quot;&gt;{{ $item-&gt;name }}&lt;/h5&gt;&lt;/a&gt;
                  &lt;div class=&quot;prch&quot;&gt;&lt;span class=&quot;card-text&quot;&gt;{{ $item-&gt;price }}&lt;/span&gt;&lt;span class=&quot;card-text&quot;&gt;&lt;i class=&quot;{{ $item-&gt;is_available_icon }}&quot;&gt;&lt;/i&gt;{{ $item-&gt;is_available_text }}&lt;/span&gt;&lt;/div&gt;&lt;br&gt;
                  &lt;div class=&quot;prch second&quot;&gt;
                  &lt;span&gt;&lt;i class=&quot;fa fa-star&quot;&gt;&lt;/i&gt;
                  &lt;i class=&quot;fa fa-star&quot;&gt;&lt;/i&gt;
                  &lt;i class=&quot;fa fa-star&quot;&gt;&lt;/i&gt;
                  &lt;i class=&quot;fa fa-star&quot;&gt;&lt;/i&gt;
                  &lt;i class=&quot;fa fa-star&quot;&gt;&lt;/i&gt;&lt;/span&gt;
                  &lt;span class=&quot;card-text feedback&quot;&gt;10 reviews&lt;/span&gt;
                  &lt;/div&gt;
                &lt;/div&gt;&lt;!--end card-body--&gt;
                &lt;div class=&quot;card-footer&quot;&gt;&lt;/div&gt;
                &lt;div class=&quot;text-center&quot;&gt;&lt;i class=&quot;fa fa-handshake&quot;&gt;&lt;/i&gt;&lt;span class=&quot;reg&quot;&gt;Ordered by 10 people&lt;/span&gt;&lt;br&gt;
                &lt;div class=&quot;product-icon-container&quot; value=&quot;Display notification&quot;&gt;
                  &lt;a href=&quot;{{ route('basket-add', [ 'id' =&gt; $item-&gt;id ]) }}&quot; class=&quot;ajaxcartadd scrollOffset btn btn-success mt-2 mb-1&quot;&gt;Add to cart&lt;/a&gt;
                  &lt;a href=&quot;{{ route('modal-order', [ 'id' =&gt; $item-&gt;id ]) }}&quot; class=&quot;modal_order btn btn-danger mt-2 mb-1&quot; data-id=&quot;{{$item-&gt;id}}&quot;&gt;Buy this item now&lt;/a&gt;
                &lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;&lt;!--end card--&gt;
            @endforeach
         @endforeach
      &lt;/div&gt;
  &lt;/section&gt;
  @endsection
  </code></pre>