У меня есть дата с флажками и кнопка проверки, которая позволяет заполнять таблицу ITEMS [] массивом, я хочу отправить этот массив на мой контроллер с помощью ajax.пожалуйста, помогите.
Вот мой с данными :
<div id='form2'>
<h3>form group 2</h3>
<h4>DATE : <span id="dateE"></span></h4>
<h4>chantier : <span id="ch"></span></h4>
<div class="form-group col-md-offset-5 ">
<button class="btn btn-success add-all" type="submit" id="hide">Pointage</button>
</div>
<table class="table table-bordered" id="mytable">
<tr>
<th>Archive</th>
<th><input type="checkbox" id="check_all"></th>
<th>S.No.</th>
<th>matricule</th>
<th>nom & prenom</th>
<th>salaire net</th>
<th>nbre de jour </th>
<th>prime</th>
</tr>
@if($salaries->count())
@foreach($salaries as $key => $salarie)
<tr id="tr_{{$salarie->id}}">
<td>archive</td>
<td><input type="checkbox" class="checkbox" data-id="{{$salarie->id}}"></td>
<td>{{ ++$key }}</td>
<td>{{ $salarie->matricule }}</td>
<td >{{ $salarie->nom }} {{ $salarie->prenom }}</td>
<td>
<input type="hidden" name="salaire" value="{{ $salarie->salairenet }}">
{{ $salarie->salairenet }}
</td>
<td ><input type="text" class='input2' name="nbreJ" class="form-control" ></td>
<td><input type="text" name="prime" class="form-control" value="0"></td>
</tr>
@endforeach
@endif
</table>
</div>
Вот мой код jquery:
$('.add-all').on('click', function() {
var items = [];
let valu = $('#datePicker').val();
$("tr").each(function(i,r) {
if ( i > 0 && $(r).find("input").first().prop("checked")) {
items.push({"matricule": r.cells[3].innerText, "salaire": r.cells[5].innerText, "date" : valu })
}
});
//ajax
$.ajax({
method : 'POST',
url : 'mois',
data : items,
success : function(data) {
if (!data.success) {
if (data.errors.name) {
$('.throw_error').fadeIn(1000).html(data.errors.name);
}
} else {
$('#success').fadeIn(1000).append('<p>' + data.posted + '</p>');
}
}
});
});
Маршрут:
Route::post('mois', 'SalarieController@addMultiple');
Контроллер:
public function addMultiple(Request $request)
{
dd($request->all());
}