百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-activitylog

> 后端框架
开源

在您的 Laravel 应用中记录活动日志

5.9K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

在您的 Laravel 应用中记录活动日志

spatie/laravel-activitylog 包提供易于使用的函数来记录应用用户的活动。它还可以自动记录模型事件。

该包将所有活动存储在 activity_log 表中。

以下是一个演示,展示如何使用它:

php
activity()->log('Look, I logged something');

你可以使用 Spatie\Activitylog\Models\Activity 模型来检索所有活动。

php
Activity::all();

这里有一个更高级的示例:

php
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'

这里有一个关于事件记录的示例。

php
$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 将返回此集合:

php
[
   'attributes' => [
        'name' => 'updated name',
        'text' => 'Lorem',
    ],
    'old' => [
        'name' => 'original name',
        'text' => 'Lorem',
    ],
];

支持我们

我们在打造一流的 开源 软件包上投入了大量资源。你可以通过购买我们的的一款付费产品来支持我们。

我们非常欢迎你从家乡给我们寄来一张明信片,并注明你正在使用我们的的哪个(些)软件包。你可以在我们的联系页面上找到我们的地址。我们会将收到的所有明信片发布在我们的的虚拟明信片墙上。

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPauditlaravellogmonitoring

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架