I Have grouped the array like below :
"2023-10-01" => IlluminateSupportCollection {#1693
#items: array:2 [
0 => array:4 [
"emp_id" => 1
"name" => "Aruna"
"code" => "DO"
"date" => "2023-10-01"
]
1 => array:4 [
"emp_id" => 2
"name" => "Aprilia"
"code" => "EVE"
"date" => "2023-10-01"
]
]
#escapeWhenCastingToString: false
}
"2023-10-03" => IlluminateSupportCollection {#1703
#items: array:2 [
0 => array:4 [
"emp_id" => 1
"name" => "Aruna"
"code" => "NIG"
"date" => "2023-10-03"
]
1 => array:4 [
"emp_id" => 2
"name" => "Aprilia"
"code" => "MID"
"date" => "2023-10-03"
]
]
#escapeWhenCastingToString: false
}
"2023-10-04" => IlluminateSupportCollection {#1694
#items: array:1 [
0 => array:4 [
"emp_id" => 2
"name" => "Aprilia"
"code" => "MID"
"date" => "2023-10-04"
]
]
#escapeWhenCastingToString: false
}
"2023-10-05" => IlluminateSupportCollection {#1690
#items: array:1 [
0 => array:4 [
"emp_id" => 2
"name" => "Aprilia"
"code" => "MID"
"date" => "2023-10-05"
]
]
#escapeWhenCastingToString: false
}
"2023-10-06" => IlluminateSupportCollection {#1689
#items: array:1 [
0 => array:4 [
"emp_id" => 2
"name" => "Aprilia"
"code" => "MID"
"date" => "2023-10-06"
]
]
#escapeWhenCastingToString: false
}
"2023-10-07" => IlluminateSupportCollection {#1688
#items: array:2 [
0 => array:4 [
"emp_id" => 1
"name" => "Aruna"
"code" => "DO"
"date" => "2023-10-07"
]
1 => array:4 [
"emp_id" => 2
"name" => "Aprilia"
"code" => "DO"
"date" => "2023-10-07"
]
]
#escapeWhenCastingToString: false
}
I would like to pass the grouped array to my table using Ajax. this is my expected table
ID | 2023-10-01 | 2023-10-02 | 2023-10-03 | 2023-10-04 | 2023-10-05 | 2023-10-06 | 2023-10-07 |
---|---|---|---|---|---|---|---|
1 | DO | NIG | DO | ||||
2 | EVE | MID | MID | MID | MID | DO |
Below is my JS code :
$.ajax({
type: "get",
url: "{{ route('schedules.fetch-table-schedule') }}",
dataType: "json",
success: function (response) {
$.each(response.result, function( index, value ) {
var body= $("<tr><td>" + value + "</td></tr>");
$("#schedule-table #body_schedule").append(body);
});
}
Sorry, but I don’t have any idea how to do it. Any help would be helpful for me. Thank you so much.