I'm not able to do as @michaeldyrynda answer is saying.
I have this array (which I passed to my function under $scheduleData variable):
array:6 [▼
"dates" => array:3 [▼
0 => Carbon {#215 ▶}
1 => Carbon {#220 ▶}
2 => Carbon {#226 ▶}
]
"starttime" => Carbon {#228 ▶}
"jobtime" => Carbon {#229 ▶}
"offsettime" => Carbon {#230 ▶}
"user_owner" => User {#236 ▶}
"users" => array:3 [▼
0 => User {#237 ▶}
1 => User {#238 ▶}
2 => User {#239 ▶}
]
]
and what i need id (even in an array or collection):
Collection {#227 ▼
#items: array:3 [▼
0 => array:1 [▼
"data" => Carbon {#215 ▶}
"starttime" => Carbon {#228 ▶}
"jobtime" => Carbon {#229 ▶}
"offsettime" => Carbon {#230 ▶}
"user_owner" => User {#236 ▶}
"users" => array:3 [▼
0 => User {#237 ▶}
1 => User {#238 ▶}
2 => User {#239 ▶}
]
]
1 => array:1 [▼
"data" => Carbon {#220 ▶}
"starttime" => Carbon {#228 ▶}
"jobtime" => Carbon {#229 ▶}
"offsettime" => Carbon {#230 ▶}
"user_owner" => User {#236 ▶}
"users" => array:3 [▼
0 => User {#237 ▶}
1 => User {#238 ▶}
2 => User {#239 ▶}
]
]
2 => array:1 [▼
"data" => Carbon {#226 ▶}
"starttime" => Carbon {#228 ▶}
"jobtime" => Carbon {#229 ▶}
"offsettime" => Carbon {#230 ▶}
"user_owner" => User {#236 ▶}
"users" => array:3 [▼
0 => User {#237 ▶}
1 => User {#238 ▶}
2 => User {#239 ▶}
]
]
]
}
I've created a blank collection and was able to separate the main dates:
$data = collect([]);
foreach($scheduleData['dates'] as $sd){
$data->push(['data' => $sd]);
}
which returned me the following structure
Collection {#227 ▼
#items: array:3 [▼
0 => array:1 [▼
"data" => Carbon {#215 ▶}
]
1 => array:1 [▼
"data" => Carbon {#220 ▶}
]
2 => array:1 [▼
"data" => Carbon {#226 ▶}
]
]
}
and then I tried to use the answer above to add the rest of the info, but with no success
$data->map(function($d){
$d['starttime'] = $scheduleData['starttime'];
return $d;
});