0

I am learning to log an activity in Laravel(7.1) using spatie/laravel-activitylog package. But when I update an user, it does not update properties column in activity_log table, I set $logAttributes attribute on model (protected static $logAttributes = ['name', 'email'];)

When I update an user like

>>> $user = User::find(1);

=> App\User {#3104
     id: 1,
     name: "John",
     email: "prath@example.com",
     email_verified_at: "2020-03-12 13:35:19",
     created_at: "2020-03-12 13:35:19",
     updated_at: "2020-03-12 13:41:34",
   }
>>> $user->update(['name' => 'James']);
=> true

and it logs that activity but returns with an empty properties column.

{
id: 8,
log_name: "default",
description: "updated",
subject_id: 1,
subject_type: "App\User",
causer_id: null,
causer_type: null,
properties: [ ],
created_at: "2020-03-12T14:58:10.000000Z",
updated_at: "2020-03-12T14:58:10.000000Z"
}
php12345
  • 31
  • 4

2 Answers2

3

In your model add these field name which you want to update:

protected static $logAttributes = ['xxx', 'yyy', 'zzz'];
protected static $logOnlyDirty = true;

php artisan config:cache
Nimantha
  • 6,405
  • 6
  • 28
  • 69
mahendra
  • 31
  • 3
0

do this for each log activity update, since all log activities are cached php artisan config:clear