tfleet/tf-activity-tracker

跟踪用户活动

0.1.2 2015-08-20 07:09 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:23:49 UTC


README

A clean and simple Laravel 4 activity logger for monitoring user activity on a website or web application.

安装

基本安装,服务提供者注册和别名设置

要安装 ActivityLog,请确保 "regulus/activity-log" 已添加到 Laravel 4 的 composer.json 文件。

"require": {
	"tfleet/activity-tracker": "0.3.0"
},

然后从命令行运行 php composer.phar update。Composer 将安装 ActivityLog 包。现在,您只需要注册服务提供者,在 app/config/app.php 中设置 ActivityLog 的别名,将以下内容添加到 providers 数组

'Regulus\ActivityLog\ActivityLogServiceProvider',

并将以下内容添加到 aliases 数组

'Activity' => 'TFleet\ActivityLog\Activity',

运行迁移并填充数据库

要从命令行运行数据库迁移(单个 DB 表),请运行以下命令

php artisan migrate --package=regulus/activity-tracker

发布配置文件

如果您想自定义 ActivityLog 的配置,您需要发布配置文件。从命令行运行以下命令

php artisan config:publish tfleet/activity-log

现在您可以在 app/config/packages/regulus/activity-log 中编辑配置文件。

基本使用

记录用户活动

Activity::log(array(
	'contentId'   => $user->id,
	'contentType' => 'User',
	'action'      => 'Create',
	'description' => 'Created a User',
	'details'     => 'Username: '.$user->username,
	'updated'     => $id ? true : false,
));

上面的代码将为当前登录的用户记录活动。IP 地址将自动保存,如果用户设置了 "developer" 会话变量为 true,则 "developer" 标志将被设置。这可以用来区分开发者和网站管理员的操作。