0377 / thinkphp-activitylog
thinkphp6.0 记录活动
V1.0
2019-11-07 10:03 UTC
Requires
- php: >=7.1.0
- nesbot/carbon: ^2.25
- topthink/framework: ^6.0.0
- topthink/think-migration: ^3.0
This package is auto-updated.
Last update: 2024-09-07 20:47:35 UTC
README
0377/thinkphp-activitylog
包提供易于使用的功能来记录您应用用户的活动。它还可以自动记录模型事件。该包将所有活动存储在 activity_log
表中。
以下是如何使用它的示例
activity()->log('Look, I logged something');
您可以使用 ice\activitylog\Models\Activity
模型检索所有活动。
Activity::select();
以下是一个更高级的示例
activity() ->performedOn($anEloquentModel) ->causedBy($user) ->withProperties(['customProperty' => 'customValue']) ->log('Look, I logged something'); $lastLoggedActivity = Activity::select()->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', ], ];
安装
您可以通过 composer 安装此包
composer require ice/thinkphp-activitylog
这是发布配置文件的目录内容
return [ /* * If set to false, no activities will be saved to the database. */ 'enabled' => Env::get('ACTIVITY_LOGGER_ENABLED', true), /* * When the clean-command is executed, all recording activities older than * the number of days specified here will be deleted. */ 'delete_records_older_than_days' => 365, /* * If no log name is passed to the activity() helper * we use this default log name. */ 'default_log_name' => 'default', /* * This model will be used to log activity. * It should be implements the ice\activitylog\Contracts\Activity interface * and extend think\Model. */ 'activity_model' => \ice\activitylog\Models\Activity::class, /* * This is the name of the table that will be created by the migration and * used by the Activity model shipped with this package. */ 'table_name' => 'activity_log', ];
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件。