i have some problem with my code. The problem is when i upload multiple file with Jquery Ajax(Front) and Laravel(Back) its only uploaded one file not all files.
index.blade.php (form)
<input type="file" name="file[]" class="form-control-file file-1">
<input type="file" name="file[]" class="form-control-file file-2">
index.blade.php (Ajax Jquery)
var data = new FormData();
data.append('file[0]', $('.file-1')[0].files[0]);
data.append('file[1]', $('.file-2')[0].files[0]);
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: '{{ url('/layanan/file/users/store') }}',
type: 'POST',
data: data,
processData: false,
contentType: false,
success: function(response){
mprogress.end();
console.log(data);
},
});
php file logic @store
$request->file[0]->move(public_path('file'), time().'.'.$request->file[0]->extension());
$request->file[1]->move(public_path('file'), time().'.'.$request->file[1]->extension());
Thanks.