diff --git a/src/Translatable/Translatable.php b/src/Translatable/Translatable.php index 0f72367..150a51e 100644 --- a/src/Translatable/Translatable.php +++ b/src/Translatable/Translatable.php @@ -14,6 +14,14 @@ trait Translatable protected $defaultLocale; + public static function bootTranslatable(): void + { + static::saved(function (Model $model) { + /* @var Translatable $model */ + return $model->saveTranslations(); + }); + } + /** * Alias for getTranslation(). * @@ -245,36 +253,6 @@ public function setAttribute($key, $value) return $this; } - /** - * @param array $options - * - * @return bool - */ - public function save(array $options = []) - { - if ($this->exists && ! $this->isDirty()) { - // If $this->exists and not dirty, parent::save() skips saving and returns - // false. So we have to save the translations - if ($this->fireModelEvent('saving') === false) { - return false; - } - - if ($saved = $this->saveTranslations()) { - $this->fireModelEvent('saved', false); - $this->fireModelEvent('updated', false); - } - - return $saved; - } - - // We save the translations only if the instance is saved in the database. - if (parent::save($options)) { - return $this->saveTranslations(); - } - - return false; - } - /** * @param string $locale *