此包的最新版本(0.0.5)没有可用的许可证信息。

用于审计数据更改

0.0.5 2024-02-27 13:01 UTC

This package is auto-updated.

Last update: 2024-09-27 14:23:45 UTC


README

Laravel Audit 是一个用于跟踪您过程中更改的 Laravel 包。它还会跟踪客户端 IP 地址、HTTP 方法、端点、用户请求、用户代理、进行更改的用户、更改的对象以及数据更改前后的数据。您需要设置对象,以便审计知道正在更改哪个模型/数据。之后,您还需要设置前后数据。

如何安装?

以下是安装此包的方法

composer require iqbalatma/laravel-audit

如何发布供应商?

您需要发布供应商(迁移和配置)。以下是发布供应商的方法

php artisan vendor:publish --provider="Iqbalatma\LaravelAudit\Providers\LaravelAuditServiceProvider"

发布迁移后,您可以运行迁移。

php artisan migrate

如何使用?

首先,您需要初始化审计服务。之后,您可以使用所有可用方法设置所有数据。

<?php

use Iqbalatma\LaravelAudit\AuditService;
use App\Models\Product;

$product = Product::create([
  "name"     => "laptop",
  "category" => "digital",
  "price"    => 10000000
]);

$audit = AuditService::init(); #initiate object

#all of this value is optional
$audit->setAction("ADD_NEW_DATA")
      ->setMessage("add new data product with category #digitcal")
      ->setTag(["#product"])
      ->setAdditional(["this could be meta data or something else"])
      ->setObject($product)
      ->setAppName("Product App") #in case you will use this package in multiple project and sharing database, you can defined the record from which app
      ->addBefore("product", null) #data before process, key product is null
      ->addAfter("product", $product); #data after process, the key of product is not null
      ->log(); #you can also write before after here log(["product" => null], ["product" => $product]), first parameter as data before, and second parameter as data after
#if your code in single function, you can just use log, without addAfter and addBefore
#but if your code in separate function, you can use that method to append key of collection
#you can also add Collection, string, array as second parameter of addAfter and addBefore
#
?>