Skip to content

Commit 72c6c70

Browse files
Update Translatable.php
1 parent 664d073 commit 72c6c70

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Translatable.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ public static function bootTranslatable()
5252
// SAVED
5353
static::saved(function (Model $model) {
5454
if ($model->wasRecentlyCreated)
55-
foreach ($model->translations as $translation)
56-
$translation->{$model->getTranslatableField()} = $model->getKey();
55+
foreach ($model->translations as $locale => &$translation) {
56+
if (is_array($translation)) {
57+
$translation = $model->translateOrNew($locale);
58+
} else {
59+
$translation->{$model->getTranslatableField()} = $model->getKey();
60+
}
61+
}
5762

5863
$model->saveTranslations();
5964
});

0 commit comments

Comments
 (0)