定制 iqbalatma/laravel-audit 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

iqbalatma/laravel-audit

最新稳定版本:1.6.0

Composer 安装命令:

composer require iqbalatma/laravel-audit

包简介

Use to auditing data changes

README 文档

README

Laravel Audit is a laravel package that use to track changes on your process. It will also track client ip address, http method, endpoint, user request, user agent, user that making changes, object that changes, before and after data changes. You need to set object to let audit know which model/data that being change. After that, you also need to set before and after data.

How to install ?

Here is how to install the package :

composer require iqbalatma/laravel-audit

How to publish vendor ?

You need to publish vendor (migration and config). Here is how to publish vendor :

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

After publishing migration, you can run the migration.

php artisan migrate

How to use ?

First you need to initiate the audit service. After that, you can set all data with available method.

<?php

use Iqbalatma\LaravelAudit\AuditService;
use App\Models\Product;
use Illuminate\Support\Facades\Auth;

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

$audit = AuditService::init(); #initiate object
#or
$audit = AuditService::init(action: "CREATE_PRODUCT", message: "Create product via method abc in class xyz", entryObject: $product, guard: "web", user: Auth::user());

#all of this value is optional
AuditService::init("CREATE_PRODUCT", "Create product via method abc in class xyz")
    ->setEntryObject($product) #required, and become optional if you already set via init
    ->addSingleTrail($role, null, $role->toArray()) #required
    ->setAppName("E-Commerce") #optional
    ->setTag(["level" => "important"]) #optional
    ->setAdditional(["role" => "ADMIN"]) #optional
    ->setActor(Auth::user()) #optional
    ->execute();


#example for data relational attach/detach
$role->fill($requestedData)->save();

$audit = \Iqbalatma\LaravelAudit\AuditService::init(AuditAction::UPDATE_ROLE, __METHOD__, $role)
    ->addSingleTrail($role, $roleBefore, $role->toArray());


$permissionBefore = $role->permissions
    ->map(fn($p) => $p->only(['id', 'name']))
    ->toArray();

$role->permissions()->sync($requestedData['permissions'] ?? []);
$role->load('permissions');

$permissionAfter = $role->permissions
    ->map(fn($p) => $p->only(['id', 'name']))
    ->toArray();

$audit->addRelationalTrail(Table::PERMISSIONS->value, $permissionBefore, $permissionAfter);

$audit->execute();
?>

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-02-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固