admicaa / laravel-activitylog-mongodb
一个用于监视您网站或应用用户的非常简单的活动记录器
Requires
- php: ^7.2
- illuminate/config: ^6.0 || ^7.0 || ^8.0
- illuminate/database: ^6.0 || ^7.0 || ^8.0
- illuminate/support: ^6.0 || ^7.0 || ^8.0
- jenssegers/mongodb: ^3.6
Requires (Dev)
- ext-json: *
- orchestra/testbench: ^4.0 || ^5.0 || ^6.0
- phpunit/phpunit: ^8.0 || ^9.0
This package is auto-updated.
Last update: 2024-09-04 05:09:32 UTC
README
该 spatie/laravel-activitylog
包提供易于使用的函数来记录您应用用户的操作。它还可以自动记录模型事件。该包将所有活动存储在 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->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://docs.spatie.be/laravel-activitylog 上找到文档。
在使用此包时遇到困难?发现了一个错误?您是否有关于活动日志的一般问题或改进建议?请随时在 GitHub 上创建一个问题,我们会尽快解决。
如果您发现了一个安全问题,请通过电子邮件 freek@spatie.be 而不是使用问题跟踪器。
安装
您可以通过 composer 安装此包
composer require admicaa/laravel-activitylog-mongodb
该包将自动注册自己。
您可以使用以下命令发布迁移
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="migrations"
注意:默认迁移假定您正在使用整数作为模型 ID。如果您正在使用 UUID 或其他格式,请在继续之前调整已发布的迁移中 subject_id 和 causer_id 字段的格式。
发布迁移后,您可以通过运行迁移来创建 activity_log
表
php artisan migrate
您可以选择使用以下命令发布配置文件
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="config"
这是已发布配置文件的内容
return [ /* * If set to false, no activities will be saved to the database. */ 'enabled' => env('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', /* * You can specify an auth driver here that gets user models. * If this is null we'll use the default Laravel auth driver. */ 'default_auth_driver' => null, /* * If set to true, the subject returns soft deleted models. */ 'subject_returns_soft_deleted_models' => false, /* * This model will be used to log activity. * It should be implements the Spatie\Activitylog\Contracts\Activity interface * and extend Illuminate\Database\Eloquent\Model. */ 'activity_model' => \Spatie\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', /* * This is the database connection that will be used by the migration and * the Activity model shipped with this package. In case it's not set * Laravel database.default will be used instead. */ 'database_connection' => env('ACTIVITY_LOGGER_DB_CONNECTION'), ];
变更日志
请参阅 CHANGELOG 了解最近更改的更多信息。
升级
请参阅 UPGRADING 了解详细信息。
测试
composer test
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 freek@spatie.be 而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件获取更多信息。