Astrotomic / laravel-translatable

A Laravel package for multilingual models
https://docs.astrotomic.info/laravel-translatable/
MIT License
1.23k stars 155 forks source link

Updated Event In translated model #268

Closed fathirasid closed 2 years ago

fathirasid commented 2 years ago

Thanks for this package .. I need to log translated model , I made a loggable trait which observe translated model events and logging it in database . But there is a problem ,When user making only update on ModelTranslation fields , the updated Event fire on only ModelTranslation , so I cannot log the main translated model . What can I do without logging ModelTranslation ?

fathirasid commented 2 years ago

We resolved this problem, when we make an update query to database, we update the timestamp of the main model like that code :

   $model->fill($request->validated());
   $model->updated_at = now();
   $model->save();

which updates the main model automatically, so it will fire update event.

Gummibeer commented 2 years ago

https://laravel.com/docs/9.x/eloquent-relationships#touching-parent-timestamps