alexgithubp/laravel-history-tracking

一个基于 https://github.com/spatie/laravel-activitylog 包的用户历史跟踪和报告系统

v1 2024-05-17 15:11 UTC

This package is not auto-updated.

Last update: 2024-09-20 16:42:02 UTC


README

Social Card of Laravel Activity Log

在您的 Laravel 应用中记录活动日志

Latest Version on Packagist GitHub Workflow Status Check & fix styling Total Downloads

一个基于 https://github.com/spatie/laravel-activitylog 包的用户历史跟踪和报告系统。该包将所有活动存储在 history_tracking 表中。

以下是一个如何使用它的演示

activity()->log('Look, I logged something');

您可以使用 Jobful\HistoryTracking\Models\HistoryTracking 模型检索所有活动。

Activity::all();

以下是一个更高级的示例

activity()
   ->performedOn($anEloquentModel)
   ->causedBy($user)
   ->withProperties(['customProperty' => 'customValue'])
   ->log('Look, I logged something');

$lastLoggedActivity = Activity::all()->last();

$lastLoggedActivity->subject; //returns an instance of an eloquent model
$lastLoggedActivity->causer; //returns an instance of your user model
$lastLoggedActivity->getExtraProperty('customProperty'); //returns 'customValue'
$lastLoggedActivity->description; //returns 'Look, I logged something'

以下是一个关于 事件记录 的示例。

$newsItem->name = 'updated name';
$newsItem->save();

//updating the newsItem will cause the logging of an activity
$activity = Activity::all()->last();

$activity->description; //returns 'updated'
$activity->subject; //returns the instance of NewsItem that was saved

调用 $activity->changes() 将返回此数组

[
   'attributes' => [
        'name' => 'updated name',
        'text' => 'Lorum',
    ],
    'old' => [
        'name' => 'original name',
        'text' => 'Lorum',
    ],
];

支持我们

我们投入了大量资源来创建 一流的开放式源代码包。您可以通过 购买我们的付费产品之一 来支持我们。

我们非常感谢您从您的家乡寄给我们明信片,说明您正在使用我们哪些包。您可以在 我们的联系页面 找到我们的地址。我们将所有收到的明信片发布在我们的 虚拟明信片墙上

文档

您可以在 https://spatie.be/docs/laravel-activitylog/introduction 上找到文档。

如果您在使用包时遇到困难?发现了错误?您是否有关于改进活动日志的一般问题或建议?请随时 在 GitHub 上创建一个问题,我们将尽快解决。

安装

您可以通过 composer 安装此包

composer require spatie/laravel-activitylog

该包将自动注册自身。

您可以使用以下命令发布迁移

php artisan vendor:publish --tag="historytrack-migrations"

注意:默认迁移假定您正在使用整数作为模型 ID。如果您正在使用 UUID 或其他格式,请在继续之前调整已发布迁移中 subject_id 和 causer_id 字段的格式。

发布迁移后,您可以通过运行迁移来创建 history_tracking

php artisan migrate

您可以选择使用以下命令发布配置文件

php artisan vendor:publish --tag="historytrack-config"

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

升级

有关详细信息,请参阅 UPGRADING

测试

composer test

贡献

有关详细信息,请参阅 CONTRIBUTING

安全性

如果您发现了关于安全性的错误,请通过 security@spatie.be 发送邮件,而不是使用问题跟踪器。

鸣谢

并特别感谢 Caneco 为标志设计和 Ahmed Nagiv4 中的所有工作。

许可

麻省理工学院许可证(MIT)。请参阅许可证文件获取更多信息。