namtrail/laravel-activity-log 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

namtrail/laravel-activity-log

最新稳定版本:1.0.2

Composer 安装命令:

composer require namtrail/laravel-activity-log

包简介

A custom laravel package for logging model activities

README 文档

README

A Laravel package that provides easy activity logging for your Eloquent models.

Installation

You can install the package via composer:

composer require NamTrail/laravel-activity-log

After installing, publish the config file and migrations:

php artisan vendor:publish --provider="NamTrail\ActivityLog\Providers\ActivityLogServiceProvider"

Then run the migrations:

php artisan migrate

Configuration

You can configure the package by editing the config/activity-log.php file:

return [
    // default table name is activity_logs. But you can also set the table name via env variable. Define ACTIVITY_LOG_TABLE_NAME variable in env file
    'table_name' => env('ACTIVITY_LOG_TABLE_NAME', 'activity_logs'),
    
    'default_log_name' => 'default',

    'default_causer_type' => '\App\Models\User',
];

Usage

Basic Usage

Add the ActivityLog trait to your model:

use NamTrail\ActivityLog\Traits\ActivityLog;

class YourModel extends Model
{
    use ActivityLog;
    
    
}

Customizing Logged Events

To customize which events you logged, add a $logEvents property to your model:

    protected $logEvents = ['created', 'updated']; // Only log creation and updates

Customizing Logged Attributes

By default, all model attributes are logged. But you will specify which attributes to log by adding a $logAttributes property:

    protected $logAttributes = ['name', 'email']; // Only log changes to these attributes

Custom Log Name

You can specify a custom log name by defineing $logName property in your model:

    
    protected $logName = 'users';
    

Accessing the Logs

You can query the activity logs using the ActivityLog model:

use NamTrail\ActivityLog\Models\ActivityLog;

// Get all logs
$logs = ActivityLog::all();

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-05-09