Replies: 2 comments 1 reply
-
Hey, for your specific described scenario: do you really need the username during event or the one the user has right now? At the end we've introduced the Because the attribute you want to always log hasn't changed, otherwise it would be dirty, you don't have to manipulate the trait but use one of the described solutions. These are upgrade save and don't conflict with future changes. As a short retro: the |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for the answer, but: Having a list where I display the activity logs, I don't really wanna get the project title through the activity subject to make the log more readable and see what project got updated. I was thinking to always store the title of the project in the log next to the dirty attributes. Also, using the activity subject to get a live object and display the title requires additional code in the activity list. If you have a lot of models, you have to write code for each of the to display a title, a name or whatever important attribute you need to display so the user viewing the activity knows which model got updated. |
Beta Was this translation helpful? Give feedback.
-
Hi guys!
I couldn't find a solution for this in the issues and discussions, so I'm going to write it here.
My problem: I want to log only dirty attributes and some attributes that should be always be in the log for tracking. For example: if I want to log changes made to a user I want it to always log the username plus the changed data. User changes e-mail address or phone, then the log should contain username, e-mail address or phone number.
I couldn't find a solution for this, so this is what I have done:
I have added a static field to my model:
protected static $alwaysLogAttributes = ['name'];
From Traits\DetectsChanges.php file I have moved the attributeValuesToBeLogged function to my model and made the following change in it:
` if ($this->shouldLogOnlyDirty() && isset($properties['old'])) {
$tmp = array_udiff_assoc(
$properties['attributes'],
$properties['old'],
function ($new, $old) {
if ($old === null || $new === null) {
return $new === $old ? 0 : 1;
}
This solution works for me for now. I would like to know if it's good to do it this way or is there a better solution to achieve this.
Thanks.
Best regards,
Bx
Beta Was this translation helpful? Give feedback.
All reactions