I do:
Model::with('animal')->get()->each(function (&$item) {
if (condition($item)) {
$item->animal = 'Yop Override';
}
})->toArray();
But I cannot override animal. Is there a way to do this?
My ugly alternative is:
array_map(function($item) {
if (condition($item)) {
$item['animal'] = 'Yop Override';
}
return $item;
}, Model::with('animal')->get()->toArray());