Having trouble saving data in the DB, even though all validations return errors when the data actually exists.
When I send the data to the backend (controller) and use dd()
to check, it shows an empty array []
.
https://i.sstatic.net/quML8.png
errors
https://i.sstatic.net/WoNlJ.png
Code
Here's my JavaScript:
$(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('.customerUpdate').on('click', function(e){
e.preventDefault();
var ordID = $(this).data('id');
var formData = new FormData();
formData.append('group_id', $('#group_id').val());
formData.append('industry_id', $('#industry_id').val());
formData.append('customername', $('#customername').val());
formData.append('companyName', $('#companyName').val());
// Attach file
formData.append('npwp', $('input[type=file]')[0].files[0]);
formData.append('province_id', $('#province_id').val());
formData.append('city_id', $('#city_id').val());
formData.append('address', $('#address').val());
formData.append('postalCode', $('#postalCode').val());
// more formData appends...
$.ajax({
type:'PUT',
url:'{{url('dashboard/customers')}}/'+ordID,
data: formData,
async: false,
cache: false,
contentType: false,
dataType: 'JSON',
enctype: 'multipart/form-data',
processData: false,
success:function(data){
alert(data.success);
}
});
});
});
Any suggestions or ideas on how to resolve this issue?