承接 rembon/laravel-auditor 相关项目开发

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

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

rembon/laravel-auditor

最新稳定版本:v2.0.0

Composer 安装命令:

composer require rembon/laravel-auditor

包简介

Laravel Eloquent Model Auditor Without Getting Sweat

README 文档

README

The Laravel Auditing package is a comprehensive auditing solution for Laravel applications. It provides a way to track changes made to your models, enabling you to maintain a detailed record of data modifications

What is Laravel Auditor

The Laravel Auditing package is designed to seamlessly integrate with your Laravel application, offering a robust and flexible solution for auditing your Eloquent models. It records every change made to your models, storing the old and new values of attributes, the user responsible for the changes, and timestamps. This allows you to maintain a detailed audit trail and ensures data integrity and accountability.

The package is highly customizable, enabling you to define which models and attributes should be audited, specify the storage location for audit logs, and configure how audits are queried and displayed. Additionally, it supports broadcasting audit events, which can be useful for triggering real-time notifications or other actions in response to data changes.

By using Laravel Auditing, you can enhance the transparency and reliability of your application, making it easier to debug issues, understand user actions, and maintain compliance with regulatory requirements.

Key Features

  • Keeping track of user actions
  • Keeping track of what the user sees
  • Keeping track of system changes
  • Keeping track of databases

When to use Laravel Auditor ?

  • Keeping track of user actions (responsibility)
  • Third party integrations (request and response)
  • Discover malicious activities in your applications
  • Debugging purposes

How to Install

Step 1: Install the Package via Composer

Run the following command in your terminal to install the package:

composer require rembon/laravel-auditor

Step 2: Register the Service Provider

Once the package is successfully installed, you need to register the service provider and publish the assets. Add the service provider to the providers array in config/app.php:

'providers' => [
    /*
    * Laravel Framework Service Providers...
    */
    ...

    /*
    * Package Service Providers...
    */
    \Rembon\LaravelAuditor\LaravelAuditorServiceProvider::class,

    /*
    * Application Service Providers...
    */
    ...
],

Use these library on top of your Event Service Provider Files app/Providers/EventServiceProvider.php:

<?php

...
use Illuminate\Mail\Events\MessageSent;
use Illuminate\Notifications\Events\NotificationSent;
use Rembon\LaravelAuditor\Listeners\AuthorizeMail;
use Rembon\LaravelAuditor\Listeners\AuthorizeNotification;

Then replace these code into app/Providers/EventServiceProvider.php

protected $listen = [
    ...
    MessageSent::class => [
        AuthorizeMail::class,
    ],
    NotificationSent::class => [
        AuthorizeNotification::class,
    ],
];

Step 3: Publish the Configuration Files

Run the following Artisan commands to publish the package configuration:

php artisan vendor:publish --tag=config
php artisan vendor:publish --tag=migrations
php artisan vendor:publish --tag=public
php artisan vendor:publish --tag=views

Step 4: Running the Migration Files

then run the migration:

php artisan migrate

if you want to migrate the specific migration, run migration below:

php artisan migrate --path=database/migrations/2050_06_14_042948_create_audits_table.php

and

php artisan migrate --path=database/migrations/2050_07_13_093233_create_performances_table.php

Step 5: Optional Commands

Lastly, run the following optional commands:

composer dump-autoload

if you are using uuid, just check these file ..._create_audits_table.php below:

Schema::create('audits', function (Blueprint $table) {
    $table->id();
    $table->foreignId('user_id')->nullable(); // modify this line into foreignUuid method, do not change the column name
    $table->string('url');
    $table->dateTime('datetime');
    $table->double('request_time');
    $table->string('route')->nullable();
    $table->json('abilities')->nullable();
    $table->json('emails')->nullable();
    $table->json('models')->nullable();
    $table->json('notifications')->nullable();
    $table->json('properties')->nullable();
    $table->timestamps();
});

How to Use ?

Simple, Just put our Auditable Traits into your models

<?php

use Rembon\LaravelAuditor\Traits\Auditable;

class User extends Authenticatable
{
    use ..., Auditable;

    ...
}

Check the view on: /auditor

System Requirements

  • PHP >= 8.0
  • Laravel <= 9.*
  • Mysql & PostgreSQL Supported

Credits

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-14