zeshan77/activity-monitor 问题修复 & 功能扩展

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

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

zeshan77/activity-monitor

Composer 安装命令:

composer require zeshan77/activity-monitor

包简介

Monitor your eloquent model activities

README 文档

README

Activity-monitor is a powerful, easy to use laravel eloquent activity monitor. We sometimes want to keep track of what's going on in a database table, who makes what changes, at what time etc. This package will help easy this for you.

Installation

You can install this package via composer using this command:

composer require zeshan77/activity-monitor

Configure the service provider as given below:

// config/app.php
'providers' => [
    ...
    \Zeshan77\ActivityMonitorServiceProvider::class,
];

Publish the migration with:

php artisan vendor:publish --provider="\Zeshan77\ActivityMonitorServiceProvider --tag="migrations"

After the migration has been published you can create the activities table by running the migrations:

php artisan migrate

Usage

Import RecordsActivity trait in eloquent model which needs to be monitored.

use Zeshan77\ActivityMonitor\RecordsActivity;

After import, use RecordsActivity trait in the model as shown below in Post model.

class Post extends Model
{
    use RecordsActivity;
    
    //
    
}

A basic Post model will look something similar below:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Zeshan77\ActivityMonitor\RecordsActivity;


class Post extends Model
{
    use RecordsActivity;

    //

}

After this, any Create, Update and Delete activities on Post model will automatically be recorded.

To retrieve all activities using eager load approach on a model, i.e Post:

>>> $post = Post::with('activity')->first();
=> App\Post {#625
     id: 1,
     body: "Body is updated.",
     created_at: "2018-02-15 18:38:45",
     updated_at: "2018-02-15 19:18:26",
     activity: Illuminate\Database\Eloquent\Collection {#665
       all: [
         Zeshan77\ActivityMonitor\Activity {#668
           id: 1,
           user_id: 1,
           subject_id: 1,
           type: "created_post",
           subject_type: "App\Post",
           old: null,
           new: "{"body":"Nemo repellendus quasi maiores ipsum vel"}",
           created_at: "2018-02-15 18:38:45",
           updated_at: "2018-02-15 17:38:45",
         },
         Zeshan77\ActivityMonitor\Activity {#669
           id: 2,
           user_id: 1,
           subject_id: 1,
           type: "updated_post",
           subject_type: "App\Post",
           old: "{"body":"Nemo repellendus quasi maiores ipsum vel"}",
           new: "{"body":"Body is updated again."}",
           created_at: "2018-02-15 18:39:12",
           updated_at: "2018-02-15 17:39:12",
         },
       ],
     },
   }
>>> 

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-29