pyaesone17 / laravel-activitylog
一个用于监视您网站或应用程序用户的非常简单的活动日志记录器
Requires
- php: ^5.0
- illuminate/config: 5.0.*
- illuminate/database: 5.0.*
- illuminate/support: 5.0.*
- spatie/string: ^2.1
Requires (Dev)
- orchestra/testbench: ^3.2
- phpunit/phpunit: 5.*
README
spatie/laravel-activity
包提供易于使用的函数来记录您应用程序用户的活动。它还可以自动记录模型事件。所有活动都将存储在 activity_log
表中。
以下是一个展示如何使用它的简单示例
activity()->log('Look, I logged something');
您可以使用 Spatie\Activitylog\Models\Activity
模型检索所有活动。
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->property('customProperty'); //returns 'customValue' $lastLoggedActivity->description; //returns 'Look, I logged something'
以下是一个关于 事件记录 的示例。
$newsItem->name = 'updated name'; $newsItem->save(); //updating the newsItem will cause an activity being logged $activity = Activity::all()->last(); $activity->description; //returns 'updated' $activity->subject; //returns the instance of NewsItem that was created
调用 $activity->changes
将返回此数组
[ 'attributes' => [ 'name' => 'updated name', 'text' => 'Lorum', ], 'old' => [ 'name' => 'original name', 'text' => 'Lorum', ], ];
Spatie 是一家位于比利时安特卫普的网页设计公司。您可以在我们的网站上找到所有开源项目的概述 在这里。
文档
您可以在 https://docs.spatie.be/laravel-activitylog/v1 上找到文档。
在使用包时遇到困难?发现了错误?您有关于改进媒体库的一般问题或建议吗?请随时在 GitHub 上 创建一个问题,我们将尽快解决。
如果您发现有关安全性的错误,请通过电子邮件 freek@spatie.be 联系,而不是使用问题跟踪器。
安装
您可以通过 composer 安装此包
composer require spatie/laravel-activitylog
接下来,您必须安装服务提供者
// config/app.php 'providers' => [ ... Spatie\Activitylog\ActivitylogServiceProvider::class, ];
您可以使用以下命令发布迁移
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="migrations"
迁移发布后,您可以通过运行迁移来创建 activity_log
表
php artisan migrate
您可以选择使用以下命令发布配置文件
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="config"
这是已发布配置文件的内容
return [ /** * When running the clean-command all recording activites older than * the number of days specified here will be deleted. */ 'delete_records_older_than_days' => 365, /** * When not specifying a log name when logging activity * we'll using this log name. */ 'default_log_name' => 'default' ];
变更日志
请参阅 CHANGELOG 以获取有关最近更改的更多信息。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 以获取详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 freek@spatie.be 联系,而不是使用问题跟踪器。
鸣谢
关于 Spatie
Spatie 是一家位于比利时安特卫普的网页设计公司。您可以在我们的网站上找到所有开源项目的概述 在这里。
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。