在您的 Laravel 应用中记录活动日志
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->getProperty('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->attribute_changes 将返回此集合:
[
'attributes' => [
'name' => 'updated name',
'text' => 'Lorem',
],
'old' => [
'name' => 'original name',
'text' => 'Lorem',
],
];我们在打造一流的 开源 软件包上投入了大量资源。你可以通过购买我们的的一款付费产品来支持我们。
我们非常欢迎你从家乡给我们寄来一张明信片,并注明你正在使用我们的的哪个(些)软件包。你可以在我们的联系页面上找到我们的地址。我们会将收到的所有明信片发布在我们的的虚拟明信片墙上。
暂无开放 Issues,或尚未同步最近议题。