Skip to content

Commit

Permalink
Update Translatable.php
Browse files Browse the repository at this point in the history
  • Loading branch information
MoamenEltouny committed Sep 20, 2021
1 parent 664d073 commit 72c6c70
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ public static function bootTranslatable()
// SAVED
static::saved(function (Model $model) {
if ($model->wasRecentlyCreated)
foreach ($model->translations as $translation)
$translation->{$model->getTranslatableField()} = $model->getKey();
foreach ($model->translations as $locale => &$translation) {
if (is_array($translation)) {
$translation = $model->translateOrNew($locale);
} else {
$translation->{$model->getTranslatableField()} = $model->getKey();
}
}

$model->saveTranslations();
});
Expand Down

0 comments on commit 72c6c70

Please sign in to comment.