Hello, is anyone there know how to add a custom property using the LogsActivity trait inside the model?
Hey,
I hope that I understood what you need. If not please add a more precise example of what you want.
If you want to add custom attributes for auto logged model events the tapActivity() method would solve it.
https://docs.spatie.be/laravel-activitylog/v3/advanced-usage/logging-model-events#tap-activity-before-logged-from-event
Hi I'm talking about adding custom properties like this activity()->withProperties(['key' => 'value']). Can we do that inside the tapActivity method? I can only see adding custom fields value example in the documents of tapActivity method.
under the Tap Activity before logged from event it says that "_This method will allow you to fill properties and add custom fields before the activity is saved._" but there is no example on how to fill properties only example on how to add custom fields.
Hey, I will close this issue. I already figured out how to customize properties using tapActivity. Thanks!
Hey, for completion: you get an instance of the Activity model in this method. So you can do everything you can do with a normal model. To add a property you can take a look in the ActivityLogger::withProperty() method.
https://github.com/spatie/laravel-activitylog/blob/2e451503a02ba98067de0f56a51ea7ceaf45487d/src/ActivityLogger.php#L87-L92
$activity->properties = $activity->properties->put($key, $value);
@Gummibeer Yes, I already figured it out. Anyways thank you!
I already closed this issue because I already found the solution. Thanks!
@blindsz Can you share example how you have done this?
Just follow @Gummibeer example above. That is how i do it.