This repository was archived by the owner on Jun 18, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +8
-30
lines changed Expand file tree Collapse file tree 1 file changed +8
-30
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,14 @@ trait Translatable
1414
1515 protected $ defaultLocale ;
1616
17+ public static function bootTranslatable (): void
18+ {
19+ static ::saved (function (Model $ model ) {
20+ /* @var Translatable $model */
21+ return $ model ->saveTranslations ();
22+ });
23+ }
24+
1725 /**
1826 * Alias for getTranslation().
1927 *
@@ -245,36 +253,6 @@ public function setAttribute($key, $value)
245253 return $ this ;
246254 }
247255
248- /**
249- * @param array $options
250- *
251- * @return bool
252- */
253- public function save (array $ options = [])
254- {
255- if ($ this ->exists && ! $ this ->isDirty ()) {
256- // If $this->exists and not dirty, parent::save() skips saving and returns
257- // false. So we have to save the translations
258- if ($ this ->fireModelEvent ('saving ' ) === false ) {
259- return false ;
260- }
261-
262- if ($ saved = $ this ->saveTranslations ()) {
263- $ this ->fireModelEvent ('saved ' , false );
264- $ this ->fireModelEvent ('updated ' , false );
265- }
266-
267- return $ saved ;
268- }
269-
270- // We save the translations only if the instance is saved in the database.
271- if (parent ::save ($ options )) {
272- return $ this ->saveTranslations ();
273- }
274-
275- return false ;
276- }
277-
278256 /**
279257 * @param string $locale
280258 *
You can’t perform that action at this time.
0 commit comments