Level 102
Are you sure the script is included on the page? Can you run the script from the browser console?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
blade.php
<select onchange="changeQuantity(event, '{{ $cart['id'] }}')" class="form-select text-center" aria-label="">
@foreach(range(1 , $product->inventory) as $item)
<option value="{{ $item }}" {{ $cart['quantity'] == $item ? 'selected' : '' }}>
{{ $item }}
</option>
@endforeach
</select>
js
<script>
function changeQuantity(event, id , cartName = null) {
//
$.ajaxSetup({
headers : {
'X-CSRF-TOKEN' : document.head.querySelector('meta[name="csrf-token"]').content,
'Content-Type' : 'application/json'
}
});
//
$.ajax({
type : 'POST',
url : '/fa/cart/quantity/change',
data : JSON.stringify({
id : id ,
quantity : event.target.value,
// cart : cartName,
_method : 'patch'
}),
success : function(res) {
location.reload();
}
});
}
</script>
Please or to participate in this conversation.