定制 tarek111/user-activity-log-pro 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

tarek111/user-activity-log-pro

最新稳定版本:v1.0.0

Composer 安装命令:

composer require tarek111/user-activity-log-pro

包简介

Full Laravel User Activity + Audit Log Package (Trait Based Auto Logging)

README 文档

README

Version: 1.0.0
Author: Tarek

Description

This package automatically logs user activities in a Laravel application. It tracks login, logout, model creation, updates, deletions, and all requests. Guest users are also tracked. Old and new data, IP address, user agent, and session info are stored for detailed auditing.

Features:

  • Use the LogActivity trait in any model to track CRUD operations.
  • Middleware logs all requests automatically.
  • Tracks both authenticated and guest users.
  • Stores old and new data on updates/deletes.
  • Captures IP, browser info, session ID, and request method.

Requirements

  • PHP >= 7.4
  • Laravel 7, 8, 9
  • Database: MySQL / PostgreSQL / SQLite

Installation & Setup

  1. Install via Composer:

License

MIT License

composer require tarek111/user-activity-log-pro


php artisan vendor:publish --provider="Tarek\UserActivityLog\UserActivityLogServiceProvider"
php artisan migrate

#Configuration
config/activitylog.php
return [
    'log_methods' => ['POST', 'PUT', 'PATCH', 'DELETE'], // Methods
    'log_guest_actions' => true, // guest actions log
];

#Usage
1. Model Trait

use Tarek\UserActivityLog\Traits\LogActivity;

class Customer extends Model
{
    use LogActivity;
}

2. Accessing Logs

UserActivityLog
use Tarek\UserActivityLog\Models\UserActivityLog;

// latest 10 logs
$logs = UserActivityLog::latest()->take(10)->get();

3. Example Columns

| Column       | Description                                   |
| ------------ | --------------------------------------------- |
| id           | Log ID                                        |
| user_id      | User ID (Guest hole null)                     |
| action       | login, logout, create, update, delete, action |
| description  | Model or action description                   |
| model        | Model class name (if applicable)              |
| model_id     | Model ID (if applicable)                      |
| old_data     | Old data before update/delete                 |
| new_data     | New data after create/update                  |
| is_logged_in | User login status                             |
| ip_address   | User IP                                       |
| user_agent   | Browser info                                  |
| method       | HTTP method                                   |
| url          | Request URL                                   |
| session_id   | Session ID                                    |
| created_at   | Timestamp                                     |

4. Logging Custom Actions
use Tarek\UserActivityLog\Helpers\ActivityLogger;

ActivityLogger::log('action', 'Custom user action', [
    'model' => Customer::class,
    'model_id' => $customer->id,
    'old_data' => $customer->getOriginal(),
    'new_data' => $customer->toArray()
]);

5. Blade Example
<table class="table table-bordered">
    <thead>
        <tr>
            <th>Log ID</th>
            <th>User</th>
            <th>Action</th>
            <th>Description</th>
            <th>Old Data</th>
            <th>New Data</th>
            <th>IP</th>
            <th>Created At</th>
        </tr>
    </thead>
    <tbody>
        @foreach($activity_logs as $log)
        <tr>
            <td>{{ $log->id }}</td>
            <td>{{ $log->user_id ?? 'Guest' }}</td>
            <td>{{ ucfirst($log->action) }}</td>
            <td>{{ $log->description }}</td>
            <td><pre>{{ json_encode($log->old_data, JSON_PRETTY_PRINT) }}</pre></td>
            <td><pre>{{ json_encode($log->new_data, JSON_PRETTY_PRINT) }}</pre></td>
            <td>{{ $log->ip_address }}</td>
            <td>{{ $log->created_at }}</td>
        </tr>
        @endforeach
    </tbody>
</table>

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固