Comments (9)
same here
from laravel-activitylog.
Depend on how you look at it, the issue is either in the trait LogsAtivity line 84, where tapActivity is called if it exists and then on line 88 the $logger->log() is called.
Or in ActivityLogger->log() method, the tapActivity is also called on line 170
from laravel-activitylog.
Same here.
It's a result of a feature introduced in this PR - #1031
There was a try to suggest a removal here - #1170 - which was blocked by the maintainers...
The solution in #1170 was good as tapActivity
is called in log()
method anyway.
from laravel-activitylog.
I'm facing the samee issue, it's kind of weird it is called a feature
from laravel-activitylog.
I faced the same issue. I try to log all activities on related sub-models on the parent-model. Therefor I use the tapActivity method on the submodel and rewrite it to the parent and add the properties to "sub-arrays"
(if there is a better way to get this result - I'm open for suggestions).
Finally my method looks like that:
public function tapActivity(Activity $activity, string $eventName): void
{
$activity->subject_type = $this->parent::class;
$activity->subject_id = $this->parent->id;
$activity->properties = $activity->properties->
map(fn($attributes) => ['relationName' => $attributes]);
}
I expected to get an entry like this:
App\Models\Activity {
...
properties: "{"attributes":{"relationName":{"value":"oldvalue"}},"old":{"relationName":{"value":"newvalue",
...
},
But indeed I get this:
I expected to get an entry like this:
App\Models\Activity {
...
properties: "{"attributes":{"relationName":{"relationName":{"value":"oldvalue"}}},"old":{"relationName":{"relationName":{"value":"newvalue"}}}}",
...
},
So it is indeed called twice in the same request with the same activity model.
Unfortunatelly this is open since several months now - Why was the PR #1170 blocked? It was never clarified, what feature would be removed since tapActivity is called anyway from the log method?!
from laravel-activitylog.
Btw: I use a very crazy workaround for it now:
public function tapActivity(Activity $activity, string $eventName): void
{
if ($activity->alreadyCalled) {
unset ($activity->alreadyCalled);
return;
}
$activity->alreadyCalled = true;
// do what you want to do herer....
}
maybe it helps somebody - sure, it will fail with a "alreadyCalled is no column in database" as soon as this problem is fixed, but I can live with that... finally it helps me removing this workarround as soon as it is not needed any more... every other workarround like detecting if the change was already there, would survive forever and never be removed....
from laravel-activitylog.
In my case, it's getting called four times, and creating three event records: updated, updated (Model) and changed (attribute). Is there a way to set it so that it only creates one event per update, rather than three?
from laravel-activitylog.
Dear contributor,
because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.
from laravel-activitylog.
How can I fix this problem? Does this actually qualify as a bug, and why hasn't this problem been fixed?
from laravel-activitylog.
Related Issues (20)
- Bulk Update Logging Not working HOT 1
- Properties empty []
- Properties empty [] HOT 1
- updateOrCreate() does not log anything HOT 1
- Log many to many doesn't work HOT 2
- Log Activity not working from inside Model boot method HOT 1
- Laravel 11 didnt register activity HOT 4
- Version 4.8.0 Call to undefined method App\Models\User::getStorableEnumValue() HOT 5
- Migration wasn't created HOT 2
- LogsActivity::$changesPipes should be cleared HOT 7
- Updated attribute not being flagged as dirty HOT 2
- Broken Link HOT 1
- Call to undefined method getStorableEnumValue() HOT 1
- Gett subject relation null HOT 2
- after install the package, unable to use the feature at volt component HOT 3
- "tapActivity" method called twice during the model event logging
- "tapActivity" method called twice during the model event logging
- Logs 5 times instead of one
- Unknown data type: 'uuid' after Laravel 11 update HOT 4
- Auto-closing PRs and Issues via GitHub/Spatie Bot
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-activitylog.