I need some help here guys, my issue is that the first console.log
returns what has been built by the foreach
, but the backend doesn't receive that same array. This foreach
basically iterates over a table, looks for a certain id, makes it an index of an array, and then it fetches all the input values from the table and pushes it to that given index.
var dateTime = [];
$("#employeeData > tr").each(function(dateIndex, date) {
dateTime[date.id] = [];
$("#" + date.id + " :input").each(function(inputIndex, inputTime) {
dateTime[date.id].push($(inputTime).val())
});
});
var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
console.log(dateTime);
$.post('employee',
{
dates: dateTime,
_token: CSRF_TOKEN
}, function(response) {
console.log(response);
}
);
});
Route::post('/employee', 'EmployeesController@updateRecords');
public function updateRecords(Request $request)
{
return $request->dates;
}
// this is a console.log of the dateTime, each date has 4 inputs
//associated with it
[2017-11-02: Array(4), 2017-11-03: Array(4), 2017-11-06: Array(4), 2017-
11-07: Array(4), 2017-11-08: Array(4), …]
This all happens when jquery handles a click event.