fix(activity): 修正操作紀錄列表描述中未顯示使用者名稱的問題
- 在 User 模型中加入 tapActivity 自動記錄 snapshot (name, username) - 在 UserController 手動紀錄的邏輯中補上 snapshot
This commit is contained in:
@@ -187,6 +187,15 @@ class UserController extends Controller
|
|||||||
->causedBy(auth()->user())
|
->causedBy(auth()->user())
|
||||||
->event('updated')
|
->event('updated')
|
||||||
->withProperties($properties)
|
->withProperties($properties)
|
||||||
|
->tap(function (\Spatie\Activitylog\Contracts\Activity $activity) use ($user) {
|
||||||
|
// Manually add snapshot since we aren't using the model's LogOptions due to saveQuietly
|
||||||
|
$activity->properties = $activity->properties->merge([
|
||||||
|
'snapshot' => [
|
||||||
|
'name' => $user->name,
|
||||||
|
'username' => $user->username,
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
})
|
||||||
->log('updated');
|
->log('updated');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,4 +57,14 @@ class User extends Authenticatable
|
|||||||
->logOnlyDirty()
|
->logOnlyDirty()
|
||||||
->dontSubmitEmptyLogs();
|
->dontSubmitEmptyLogs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tapActivity(\Spatie\Activitylog\Contracts\Activity $activity, string $eventName)
|
||||||
|
{
|
||||||
|
$activity->properties = $activity->properties->merge([
|
||||||
|
'snapshot' => [
|
||||||
|
'name' => $this->name,
|
||||||
|
'username' => $this->username,
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user