承接 dual/kronikl 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dual/kronikl

Composer 安装命令:

composer require dual/kronikl

包简介

A model history tracking library for Laravel.

README 文档

README

A model history tracking library for Laravel.

Installation

Install the package via composer:

composer require dual/kronikl

This will include Kronikl in your project. Now, publish the configuration file and the migration file:

php artisan vendor:publish --provider="Dual\Kronikl\KroniklServiceProvider"

Finally, run the migration:

NOTE: If you are using UUID primary keys, replace instances of unsignedBigInteger with uuid before migrating.

php artisan migrate

Configuration

By default, create, update, delete and restore operations performed via Eloquent are observed. This means you do not need to call any other function, simply include the models you want to watch in the models key in the configuration file (config/kronikl.php).

Options are documented in config/kronikl.php and are provided with sane defaults. Feel free to modify as needed.

By default, password is defined in the discards key for security purposes. Please do not remove this unless you know what you're doing.

Records

Audit trail records are saved in the kronikl_logs table and is automatically created upon every successful created, updated and deleted event monitored by an observer. Records are stored in JSON and can be searched via fuzzy search (using LIKE direct in the record column), or by using Laravel's whereJsonContains() method for more specific results.

What does it look like?

The actual record is stored as JSON, so it's easy to do a json_decode() on the record and call whatever record you want to use. For example:

<?php

// ... other code here ... //

// Get a trail record (define your own conditions here)
$trail = Kronikl::where('user_id', $user->id)->where('action', 'update')->first();

// Decode the JSON
$result = json_decode($trail->record);

// Output the old and new values
echo "Old value: " . $result->name->old . "<br>";
echo "New value: " . $result->name->new;

On update, it only saves the fields that actually changed (and because we're using observers, calling update() with the same data won't record a new entry)

It's clean and coherent, you can modify your spiels to look however you want, since we only store the data and not how it's constructed. In JSON, it looks like the following (an example of a create action log):

{ 
   "name":{ 
      "old": "John Smith",
      "new": "Jose Rizal"
   },
   "email":{ 
      "old": "john.smith@example.com",
      "new": "jose.rizal@example.com"
   }
}

Discarding Data

Global Discards

You can discard a field name globally by setting it in config/kronikl.php.

<?php

return [
    /**
     * Specify which fields (columns) to discard in the log for data changes.
     *
     * For security purposes, "passsword" and "remember_token" are included below.
     * Since we are already recording event changes with timestamps, we also included
     * created_at, updated_at, deleted_at and banned_at by default.
     */
    "discards" => [
        "password",
        "remember_token",
        "created_at",
        "updated_at",
        "deleted_at",
        "banned_at"
    ]
];

Model-specific Discards

In addition, if you want to discard a field specific to a model, you may add a public $discarded declaration in your model:

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The keys defined in this array is discared by Kronikl.
     *
     * @var array
     */
    public $discarded = [
        'password'
    ];
}

Never store sensitive data in plaintext. Sane defaults have been provided (see config/kronikl.php), adjust as necessary.

License

This library is published under the MIT Open Source license.

dual/kronikl 适用场景与选型建议

dual/kronikl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 dual/kronikl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dual/kronikl 我们能提供哪些服务?
定制开发 / 二次开发

基于 dual/kronikl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-26