Old PHP user here but new to Laravel, I need help(answers or link to related solution)...
If I have a relation model(or collection, I get confused here)...
$data = MyData::with('new_data')->first();
resulting with...
data = {
a: 1,
b: 2,
new_data: {
c: 3
}
}
Is there an easy eloquent or collection function to merge new_data key pairs to the parent data? such that will result to this...
data = {
a: 1,
b: 2,
c: 3
}
I've tried flatten, flatMap, mapWithKeys, and other examples but failed to get the results I wanted. If there's no easy solution to this, this would be my long approach...
$raw_data = MyData::with('new_data')->first();
$data = collect($raw_data)->put('c', $raw_data->new_data->c);
thanks!