Open peirix opened 6 days ago
I got the same issue. Try to log on changing User roles with: following code, and dd found old and attributes got the same value
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly(['name', 'email', 'password', 'roles'])
->logOnlyDirty()
->dontSubmitEmptyLogs();
}
public function tapActivity(Activity $activity, string $event)
{
/** @var Collection $properties */
if ($properties = $activity->properties) {
dd($activity->changes());
if ($properties->has('old')) {
$old = $properties->get('old');
if (isset($old['password'])) {
$old['password'] = '<secret>';
}
if (isset($old['roles'])) {
$oldRoleNames = [];
if (is_array($old['roles'])) {
foreach ($old['roles'] as $oldRole) {
$oldRoleNames[] = $oldRole['name'];
}
$old['roles'] = implode(',', $oldRoleNames);
}
}
$properties->put('old', $old);
}
if ($properties->has('attributes')) {
$attributes = $properties->get('attributes');
if (isset($attributes['password'])) {
$attributes['password'] = '<new secret>';
}
if (isset($attributes['roles'])) {
$roleNames = [];
if (is_array($attributes['roles'])) {
foreach ($attributes['roles'] as $role) {
$roleNames[] = $role['name'];
}
$attributes['roles'] = implode(',', $roleNames);
}
}
$properties->put('attributes', $attributes);
}
$activity->properties = $properties;
}
}
Describe the bug Basically the same as #1081 but that got closed, so thought I'd create a new one.
We have an
Item
class that has a many-to-many relationship toColor
through the colors():And then our
getActivitylogOptions
is set up as following:The first thing is that I can't tell it to log
['colors.id']
which I would like to, I then get an error sayingid
attribute does not exist on collection. But also theold
colors array and theattribute
colors array are always the same. And I found that if I sync the colors first the arrays will have the new value, and if I save the item before syncing the colors it will have the old valueTo Reproduce
Expected behavior First off I would expect the arrays to be different, but I would also like to be able to specify what attribute of the related model I would like to be in the array
Versions (please complete the following information)