insowe/datalogger 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

insowe/datalogger

Composer 安装命令:

composer require insowe/datalogger

包简介

Save data logs to Cloud Storage.

README 文档

README

This package help log the data after every updated, and upload to cloud storage not database to reduce loading of the database.

Installation

Via Composer

$ composer require insowe/datalogger

Execute php artisan vendor:publish, choose Provider: Insowe\DataLogger\DataLoggerServiceProvider to publish database migration to ~/database/migrations/2020_01_22_023910_create_data_logs_table.php.

You should put all the data types you need to enum column setting.

Schema::create('data_logs', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->enum('data_type', [

    // Put data types of the app here!

    ])->comment('資料類型');

For example:

Schema::create('data_logs', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->enum('data_type', [
        Model::getDataLogType(),
        Product::getDataLogType(),
        CleaningService::getDataLogType(),
    ])->comment('資料類型');

This package use queue, make sure the queue environment is ready, or just let QUEUE_CONNECTION=sync.

Usage

If an Eloquent Model will be logged, let it implement the interface Insowe\DataLogger\Models\IData.

class Model extends BaseModel implements IData
{
    public function getDataLogId()
    {
        return $this->id;
    }
    
    public static function getDataLogType()
    {
        return 'model';
    }
}

Create a createLog method in the controller after data has beed updated.

public function createOrUpdate(Request $request)
{
    if (intval($request->id) === 0) {
        $item = $this->create($request);
    }
    else {
        $item = $this->update($request);
    }
    $this->createLog($item->id, $request->user()->id);
}

In the method createLog,get the newest data and trigger the event Updated, the listener will add a log row to database and make a queue for upload log file to the cloud.

public function createLog($modelId, $userId)
{
    $item = Model::with('brand')
            ->with('type')
            ->with('age')
            ->with('minAge')
            ->with('usages')
            ->with('detail')
            ->with('accessories')
            ->where('id', $modelId)
            ->first();
    
    $item->setHidden([
        'product_quantity',
        'product_in_stock',
        'updated_at',
        'deleted_at',
    ]);
    
    event(new Updated($item, $userId));
}

Notice: should hide the machine-updated columns like updated_at, deleted_at and other statistics columns.

Change log

Please see the changelog for more information on what has changed recently.

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

License

license. Please see the license file for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2020-04-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固