victordrnd/laravel-activitylog

一个非常简单的活动日志记录器,用于监控您的网站或应用的用户


README

Latest Version on Packagist Build Status Code coverage Quality Score StyleCI Total Downloads

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 spatie/laravel-activitylog

该包将自动注册自己。

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

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发送邮件,而不是使用问题跟踪器。

明信片软件

您可以使用此包,但如果它进入您的生产环境,我们非常感谢您从您的家乡给我们寄一张明信片,说明您正在使用我们的哪个包。

我们的地址是:Spatie,Samberstraat 69D,2060 安特卫普,比利时。

我们将发布所有收到的明信片在我们的公司网站上

致谢

支持我们

斯帕蒂是一家位于比利时的安特卫普的网页设计公司。您可以在我们的网站上找到我们所有开源项目的概述。请点击这里

您的业务是否依赖于我们的贡献?请在 Patreon 上联系我们并支持我们。所有承诺都将用于分配人力进行维护和开发新功能。

许可证

MIT许可证(MIT)。有关更多信息,请参阅 许可证文件