0

我正在学习使用spatie/laravel-activitylog包在 Laravel(7.1) 中记录活动。但是当我更新用户时,它不会更新表properties中的列activity_log,我在模型( )上设置$logAttributes 了属性protected static $logAttributes = ['name', 'email'];

当我更新用户时

>>> $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

它记录该活动,但返回一个空的属性列。

{
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"
}
4

1 回答 1

3

在您的模型中添加您要更新的这些字段名称:

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

php artisan config:cache
于 2020-05-22T07:36:54.683 回答