【发布时间】:2020-01-05 09:32:24
【问题描述】:
我想在Laravel Auditing 日志中存储新数据,并在Laravel Auditing 使用的自动日志中注册新字段。我正在尝试在Laravel Auditing 的表中添加一个新字段,以便在审核完成后记录自定义数据。我正在使用几乎全新的Laravel 5.8.31 安装。
我正在向audits 表的存储中添加新数据。我正在修改迁移文件2019_08_26_083436_create_audits_table.php 中的表字段以添加新的自定义字段。
Schema::create('audits', function (Blueprint $table) {
$table->increments('id');
$table->string('user_type')->nullable();
$table->unsignedBigInteger('user_id')->nullable();
$table->string('event');
$table->morphs('auditable');
$table->text('old_values')->nullable();
$table->text('new_values')->nullable();
$table->text('url')->nullable();
$table->ipAddress('ip_address')->nullable();
$table->string('user_agent')->nullable();
$table->string('tags')->nullable();
$table->timestamps();
$table->text('custom')->nullable(); <--- Like this one
$table->index(['user_id', 'user_type']);
});
我已经修改了这个解析函数,试图在新字段中存储一些东西,但它没有。
\My-project\vendor\owen-it\laravel-auditing\src\Audit.php
public function resolveData(): array
{
$morphPrefix = Config::get('audit.user.morph_prefix', 'user');
// Metadata
$this->data = [
'audit_id' => $this->id,
'audit_event' => $this->event,
'audit_url' => $this->url,
'audit_ip_address' => $this->ip_address,
'audit_user_agent' => $this->user_agent,
'audit_tags' => $this->tags,
'audit_created_at' => $this->serializeDate($this->created_at),
'audit_updated_at' => $this->serializeDate($this->updated_at),
'user_id' => $this->getAttribute($morphPrefix.'_id'),
'user_type' => $this->getAttribute($morphPrefix.'_type'),
'custom' => 'Custom Value', <--- Some new value
];
它应该在'custom' 字段中存储'Custom Value',但它只是不存储任何内容。我可能正在查看错误的函数,或者这可能不是他审核新自定义数据的方式。
【问题讨论】: