laravel-activitylog支持中文搜索

宇文修筠
2023-12-01

1、laravel-activitylog简介

  • github地址
  • 官方文档
  • 功能:自动或手动生成日志,其中最好用的是通过设置对Laravel model增删改进行自动记录dirty attributes
  • 缺点:记录中文的时候会自动unicode序列化,查询的时候不方便

2、改进缺点方式一

打开vendor目录下Spatie\laravel-activitylog\src\Models\Activity.php 添加如下代码段

    /**
     * 如果变更的字段是`properties`,则`json_encode`的时候不要进行`Unicode`编码
     * @inheritDoc
     */
    public function setAttribute($key, $value)
    {
        // take special care for the attributes `properties`
        if (in_array($key, ['properties'])) {
            $this->attributes[$key] = json_encode($value, JSON_UNESCAPED_UNICODE);

            return $this;
        }

        // apply default for everything else
        return parent::setAttribute($key, $value);
    }
复制代码

3、其他解决方式

暂时没找到

 类似资料: