I am currently encountering an issue while attempting to pass an array through an AJAX request.
<input type="text" name="item_name[]">
<input type="text" name="address">
$(document).on('click', '#save_info', function () {
var address = $("#address").val();
var item_name = $("[name^='item_name']");
$.ajax({
url: '/save_information',
dataType: "json",
type: 'POST',
data: {
_token: '{{ csrf_token() }}',
address: address,
item_name: item_name,
}
});
});
Upon checking my controller, I attempted to access the item_name variable from the request but encountered an error. The code snippet below shows my attempt:
$item_name = $request->item_name;
$array_count = count($item_name);
This implementation is causing an error for me. Could someone provide guidance on how to correctly save array values using a loop? Thank you in advance.