-
-
Notifications
You must be signed in to change notification settings - Fork 718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't log Translatable fields. #647
Comments
Hey, thanks for reaching out. Right now there isn't any special implementation to work with the translatable package. And yes, you are right that it logs english because of your app locale. This package only logs the attribute like |
@Gummibeer Thanks for your comment. Could you please explain some more info for the code in the trait? |
I think that you will have to override. laravel-activitylog/src/Traits/DetectsChanges.php Lines 121 to 150 in 195887d
Inside the loop you will have to check if the attribute is translatable. If so you will have to retrieve all translation data for this attribute. After this you will already be done (I think in theory). laravel-activitylog/src/Traits/DetectsChanges.php Lines 17 to 24 in 195887d
I haven't tested the logging with arrays - so it could be that you will have to adjust following if you only want to log dirty fields. laravel-activitylog/src/Traits/DetectsChanges.php Lines 81 to 119 in 195887d
If you need more help just ask. I'm happy to help. Possibly we will keep a list or even maintain the code in this repo as some kind of other spatie compatibility traits. |
+1 |
1 similar comment
+1 |
@romualdbrisson & @DonDiegoAA could you please use the comment reactions or write full comments? Because this is a very specific issue that's based on a more general one I would like to solve the general one instead of implementing hundreds of custom solutions. |
Hello @Gummibeer , this +1 meant "I have this problem too and I'm interested in a solution". |
In #801 i created a simple function you can override to implement your own way of collecting the data to report per attribute.
In your Model class, or in a trait that gets used in your models. |
it seems
public function tapActivity(Activity $activity, string $eventName)
{
if (
$eventName != 'deleted' ||
method_exists($this, 'isForceDeleting') && !$this->isForceDeleting()
) {
$props = $activity->properties;
$props_o = $props['old'] ?? [];
$props_a = $props['attributes'] ?? [];
$trans = $this->getTranslatableAttributes();
$keys = $this->checkForTransKeys($props_o, $trans) ?: $this->checkForTransKeys($props_a, $trans);
if ($keys) {
$orig = $this->getOriginal();
$dirty = $this->getDirty();
$old = [];
$new = [];
foreach ($keys as $key) {
$old += [$key => isset($orig[$key]) ? json_decode($orig[$key], true) : []];
$new += [$key => isset($dirty[$key]) ? json_decode($dirty[$key], true) : []];
}
$activity->properties = [
'old' => array_merge($props_o, $old),
'attributes' => array_merge($props_a, $new),
];
}
}
return $activity;
}
protected function checkForTransKeys($arr, $trans)
{
return array_intersect(array_keys($arr), $trans);
} |
Update if the changed key is not in the current locale, the
so to get around this, |
I will close this issue even if v4 isn't released yet. But the task itself is done and I want to check which tasks are really open. Please keep an eye on #787 |
Hi,
I am trying to log only changed attributes by using
protected static $logOnlyDirty = true;
in my model, but this is not working if I'm using translatable attributes package by Spatie. it logs only English attributes and I think that's because my app locale is English.I am using Laravel Framework 6.9.0 and spatie/activity-log ^3.9
Thank you.
The text was updated successfully, but these errors were encountered: