@@ -48,31 +48,36 @@ public function mutateFormDataBeforeFill(array $data): array
4848 }
4949
5050 protected function handleRecordUpdate (Model $ record , array $ data ): Model
51- {
52- /** @var Model&TranslatableContract $record */
53- if (! $ this ->lang ) {
54- return parent ::handleRecordUpdate ($ record , $ data );
55- }
51+ {
52+ /** @var Model&TranslatableContract $record */
53+ if (! $ this ->lang ) {
54+ return parent ::handleRecordUpdate ($ record , $ data );
55+ }
5656
57- if (! property_exists ($ record , 'translatedAttributes ' )) {
58- return parent ::handleRecordUpdate ($ record , $ data );
59- }
57+ if (! property_exists ($ record , 'translatedAttributes ' )) {
58+ return parent ::handleRecordUpdate ($ record , $ data );
59+ }
6060
61- $ translation = $ record ->translations ()->firstOrNew ([
62- 'locale ' => $ this ->lang ,
63- ]);
61+ // Save translation manually
62+ $ translation = $ record ->translations ()->firstOrNew ([
63+ 'locale ' => $ this ->lang ,
64+ ]);
6465
65- foreach ($ record ->translatedAttributes as $ attr ) {
66- if (array_key_exists ($ attr , $ data ['translations ' ][$ this ->lang ])) {
67- $ translation ->setAttribute ($ attr , $ data ['translations ' ][$ this ->lang ][$ attr ]);
68- }
66+ foreach ($ record ->translatedAttributes as $ attr ) {
67+ if (array_key_exists ($ attr , $ data ['translations ' ][$ this ->lang ] ?? [])) {
68+ $ translation ->setAttribute ($ attr , $ data ['translations ' ][$ this ->lang ][$ attr ]);
6969 }
70- $ translation ->save ();
70+ }
71+ $ translation ->save ();
7172
72- $ record ->update ($ data );
73+ // Remove 'translations' from data before update
74+ unset($ data ['translations ' ]);
75+
76+ $ record ->update ($ data );
77+
78+ return $ record ;
79+ }
7380
74- return $ record ;
75- }
7681
7782 public function mutateFormDataBeforeSave (array $ data ): array
7883 {
0 commit comments