定制 nh/trackable 二次开发

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

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

nh/trackable

Composer 安装命令:

composer require nh/trackable

包简介

Make a Laravel model trackable

README 文档

README

Install the package via composer:

composer require nh/trackable

Publish the translation and the model for the trackable:

php artisan vendor:publish --tag=trackable

To make a model trackable, add the Trackable trait to your model: To retrieve the tracks of your model => $post->tracks To check if of your model has any tracks => $post->hasTracks()

use Nh\Trackable\Traits\Trackable;

use Trackable;

The events available for the model are:

  • created
  • updated
  • deleted
  • soft-deleted
  • restored
  • force-deleted
  • saved
  • changed

You can retrieve the tracks (order by date and id) of a model:

$model->tracks;

Or you can retrieve the most recent track

$model->latestTrack;

Model

You can retrieve multiple information per track: You can customize the translations, colors and icons via the trackable config file

$track->event_name;       // The translated name of the event
$track->event_color;      // The color of the event
$track->event_icon;       // The icon of the event
$track->model;            // The clean model name
$track->model_name;       // The translated model name
$track->relation_model;   // The clean relation model name
$track->relation_name;    // The translated relation model name
$track->relation_icon;    // The icon of the relation model
$track->username;         // The username
$track->time;             // The formated time
$track->formated // Return 'Updated <b>3m ago</b> by <b>Natacha</b>'

Add a track

You can add a custom track for a model:

$model->addTrack('my-event', $relationModel, $numberRelationModelAffected, 'My comment')

Event listener

You can track some event by using the listener AddTrack.

Add this lines to your property $listen in your App\Providers\EventServiceProvider.php :

Your event should return:

  • $event->name as the name of the event (exemple: created)
  • $event->model as the model who is tracked)
  • $event->relation as the model relation (exemple: App\Models\Role)
  • $event->number as the number of items affected (model or relation) by the event
MyCustomEvent::class => [
    \Nh\Trackable\Listeners\AddTrack::class
]

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固