linearsoft/laravel-activitylog-backport

将Spatie的Laravel-ActivityLog移植到PHP 5.6

1.15.3 2017-07-07 20:41 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:36:59 UTC


README

这是一个后移植包,允许Laravel-ActivityLog与PHP 5.6一起工作。设计上保留了原始项目的命名空间 Spatie\Activitylog。这允许通过仅进行少量修改即可完全使用文档。

安装

更改

composer require spatie/laravel-activitylog

composer require linearsoft/laravel-activitylog-backport

为了方便,已在此后移植版本中恢复了活动外观基础设施。你只需注册外观即可。

// config/app.php
'aliases' => [
    ...
    'Activity' => Spatie\Activitylog\ActivitylogFacade::class,
];

测试

已从后移植版本中移除所有测试。

错误或功能请求

大多数错误和请求应提交给Spatie团队。修复和功能最终将回移植到本项目。

然而,如果你发现了后移植版本的具体问题,请通过GitHub提交。

许可

许可已从MIT修改为GPLv3许可证 - 有关详细信息,请参阅LICENSE文件。然而,仍要求您遵守原始包的Postcardware "要求"。

原始ReadMe.md开始

在您的Laravel应用程序中记录活动

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->getExtraProperty('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是一家位于比利时安特卫普的网页设计公司。您可以在我们的网站上找到我们所有开源项目的概述这里

Postcardware

您可以免费使用此包(它具有MIT许可),但如果它进入了您的生产环境,我们非常希望您能从您家乡寄给我们一张明信片,注明您正在使用我们的哪个包。

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

最好的明信片将被发布在我们的网站上开源页面。

文档

您可以在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"

注意:默认迁移假设您正在使用整数作为您的模型ID。如果您正在使用UUID或某些其他格式,请在继续之前调整已发布迁移中subject_id和causer_id字段的格式。

迁移发布后,您可以通过运行迁移来创建 activity_log 表。

php artisan migrate

您可以选择使用以下命令发布配置文件:

php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="config"

这是已发布配置文件的内容

return [

    /**
     * When set to false, no activities will be saved to database.
     */
    'enabled' => env('ACTIVITY_LOGGER_ENABLED', true),

    /**
     * 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',


    /**
     * When set to true, the subject returns soft deleted models.
     */
     'subject_returns_soft_deleted_models' => false,
     
     
    /**
     * This model will be used to log activity. The only requirement is that
     * it should be or extend the Spatie\Activitylog\Models\Activity model.
     */
    'activity_model' => \Spatie\Activitylog\Models\Activity::class,     
];

变更日志

有关最近更改的详细信息,请参阅变更日志

测试

$ composer test

贡献

有关详细信息,请参阅贡献指南

安全性

如果您发现任何安全相关的问题,请发送电子邮件至 freek@spatie.be,而不是使用问题跟踪器。

鸣谢

关于Spatie

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

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息.