Skip to content

Commit

Permalink
fix error on create
Browse files Browse the repository at this point in the history
  • Loading branch information
bastihilger committed Feb 11, 2021
1 parent 87b73a2 commit 6783217
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/TranslatableFieldMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,20 @@ public function translatable()
$this->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locales) {
$realAttribute = FieldServiceProvider::normalizeAttribute($this->meta['translatable']['original_attribute'] ?? $attribute);
$translations = $request->{$realAttribute};
foreach ($locales as $localeKey => $localeName) {
$model->translate($localeKey)->{$realAttribute} = $translations[$localeKey];

if($request->editMode == 'create') {

foreach ($locales as $localeKey => $localeName) {
$translationEntry = $model->translateOrNew($localeKey);

$translationEntry->{$realAttribute} = $translations[$localeKey];
}
} else {
foreach ($locales as $localeKey => $localeName) {
$model->translate($localeKey)->{$realAttribute} = $translations[$localeKey];
}
}

});

return $this;
Expand Down

0 comments on commit 6783217

Please sign in to comment.