Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/Value/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,22 @@ class Resolver implements ResolverInterface
*/
public function set($model, $attribute, $groups)
{
return $model->$attribute = $groups->map(function($group) {
$modelAttribute = $model->$attribute;
return $model->$attribute = $groups->map(function($group) use ($modelAttribute) {

// Merge old attributes with the new ones to avoid override File/ Image Fields when nested Images
if(isset($modelAttribute)){
foreach ($modelAttribute as $oldAttribute) {
if($oldAttribute['key'] == $group->key()) {
return [
'layout' => $group->name(),
'key' => $group->key(),
'attributes' => array_merge($oldAttribute['attributes'], $group->getAttributes())
];
}
}
}

return [
'layout' => $group->name(),
'key' => $group->key(),
Expand Down Expand Up @@ -66,4 +81,4 @@ protected function extractValueFromResource($resource, $attribute)
}, $value);
}

}
}