Laravel Activity Log and JWT user
I use Activity Log from spatie (https://github.com/spatie/laravel-activitylog) to keep track of changes on my models.
I opened an issue on Github, but since it isn't a bug and there might be a way to do it, I open a thread here too.
I have a model called Documents that I want to log the activity. On the Document.php file I have added this code:
protected static $logAttributes = [
'expired',
'published',
'title'
];
If I keep only this, then the causedBy are not included on the logs (I use JWT auth for a REST API). If I add this on my controller during the update of document:
$user = JWTAuth::parseToken()->authenticate();
activity()
->causedBy($user)
->performedOn($document)
->log('new');
I have a new log entry with the causedBy user, but then I don't have the attributes values I added on the Model.
So I ended up with one line with attributes and without user and one line with user but without attributes.
Any idea how I could include the causedBy on my model's file instead of each of the actions (create, update, etc)?
Please or to participate in this conversation.