I'm having an issue adding to the cart in laravel 8 with an ajax request When I click on the add to cart button an alert is supposed to pop but instead, I get the 500 (Internal Server Error) displayed on the console
First of all, I will show you my js code:
$('.addToCartBtn').click(function (e) {
e.preventDefault();
var product_id = $(this).closest('.product_data').find('.prod_id').val();
var product_qty = $(this).closest('.product_data').find('.qty-input').val();
var flavour_id = $(this).closest('.product_data').find('.flav_select').val();
var size_id = $(this).closest('.product_data').find('.size_select').val();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type:"POST",
//_method: "PUT",
url:"/add-to-cart",
data: {
'product_id':product_id,
'product_qty':product_qty,
'flavour_id':flavour_id,
'size_id':size_id,
},
success: function (response) {
alert(response.status ) ;
}
});
});