定制 alizharb/filament-activity-log 二次开发

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

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

alizharb/filament-activity-log

Composer 安装命令:

composer require alizharb/filament-activity-log

包简介

A powerful, feature-rich activity logging solution for FilamentPHP v4 & v5 with timeline views, dashboard widgets, and revert actions.

README 文档

README

Filament Activity Log

License Latest Version on Packagist Total Downloads PHP Version

A powerful, feature-rich activity logging solution for FilamentPHP v4 & v5
Seamlessly track, view, and manage user activities with beautiful timelines and insightful dashboards.
Built on spatie/laravel-activitylog

📖 Table of Contents

✨ Features

🎯 Core Functionality

  • 📦 Full Resource Integration - Dedicated resource to browse, filter, and search logs
  • ⏱️ Timeline View - Stunning slide-over timeline to visualize record history
  • 📊 Insightful Widgets - Activity charts and latest activity tables
  • 🛡️ Audit Risk Scoring - Surface high-risk and critical activity before it gets buried
  • 🔒 Privacy-Safe Redaction - Mask secrets in diffs, raw data, exports, and UI views
  • 🏛️ Compliance Mode - Optional immutable mode for audit trails that should not be changed from the panel
  • 🔗 Relation Manager - Add activity history to any resource
  • 🎨 Highly Customizable - Configure labels, colors, icons, and visibility
  • 🔐 Role-Based Access - Fully compatible with Filament's authorization
  • 🌍 Dark Mode Support - Beautiful in both light and dark modes

📋 Requirements

Requirement Version Status
PHP 8.3+
Laravel 12 / 13
Filament v4+ / v5+

Dependencies:

Spatie Activitylog Compatibility

Spatie Version Support Notes
^4.0 Full Legacy support with native batch_uuid and properties-based tracking
^5.0 Full Requires the official v5 upgrade migration (see below)

Important for v5 users: You must follow Spatie's official v5 upgrade guide before using this plugin on v5. This includes:

  1. Adding the attribute_changes column
  2. Dropping the batch_uuid column
  3. Migrating tracked change data from properties into attribute_changes

The plugin does not support an unmigrated v5 database.

Key differences between v4 and v5:

  • Tracked changes: v4 stores changes in properties['attributes'] / properties['old']. v5 uses the dedicated attribute_changes column. The plugin reads from both automatically.
  • Batch grouping: v4 uses the native batch_uuid column. v5 uses custom-property grouping (properties['group']) per the official docs. The plugin handles both transparently.
  • Relationships: v5 renames activities() to activitiesAsSubject() and actions() to activitiesAsCauser(). The plugin detects and uses whichever is available.

⚡ Installation

Step 1: Install via Composer

composer require alizharb/filament-activity-log

Step 2: Register the Plugin

Add to your AdminPanelProvider:

use AlizHarb\ActivityLog\ActivityLogPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            ActivityLogPlugin::make()
                ->label('Log')
                ->pluralLabel('Logs')
                ->navigationGroup('System')
                ->cluster('System'), // Optional: Group inside a cluster
        ]);
}

Step 3: Install Assets & Config

Run the installation command to publish the configuration, assets, and migrations:

php artisan filament-activity-log:install

🎯 Quick Start

1. Enable Logging on Models

Ensure your models use the LogsActivity trait:

use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;

class User extends Authenticatable
{
    use LogsActivity;

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logAll();
    }
}

2. Configure Tracking (Optional)

To automatically capture IP addresses and user agent information, add the generic tap to your config/activitylog.php:

'activity_logger_taps' => [
    \AlizHarb\ActivityLog\Taps\SetActivityContextTap::class,
],

3. View Activities

Navigate to the Logs resource in your admin panel to see all tracked activities.

🎯 Core Features

📦 Activity Log Resource

A dedicated resource allows you to manage all activity logs.

Features:

  • Advanced Filtering - Filter by causer, subject, event type, and date
  • Global Search - Search through log descriptions and properties
  • Detailed View - Inspect every detail of an activity log
  • Risk Badges - Quickly spot sensitive, destructive, or security-related changes
  • Privacy Redaction - Sensitive fields are masked before display by default

⏱️ Timeline View

Visualize the history of any record with a beautiful timeline.

Usage: The timeline is available as a table action in the Relation Manager or can be added to any page.

📊 Dashboard Widgets

Activity Chart Widget

Displays a line chart showing activity trends over time.

use AlizHarb\ActivityLog\Widgets\ActivityChartWidget;

public function getWidgets(): array
{
    return [
        ActivityChartWidget::class,
    ];
}

Latest Activity Widget

Shows a list of the most recent activities.

use AlizHarb\ActivityLog\Widgets\LatestActivityWidget;

public function getWidgets(): array
{
    return [
        LatestActivityWidget::class,
    ];
}

🔗 Relation Manager

Add an activity log history table to any of your existing resources (e.g., UserResource).

use AlizHarb\ActivityLog\RelationManagers\ActivitiesRelationManager;

public static function getRelations(): array
{
    return [
        ActivitiesRelationManager::class,
    ];
}

🏷️ Customizable Subject Titles

The package automatically checks for name, title, or label attributes on your models. For more control, implement the HasActivityLogTitle interface on your model:

use AlizHarb\ActivityLog\Contracts\HasActivityLogTitle;

class User extends Model implements HasActivityLogTitle
{
    public function getActivityLogTitle(): string
    {
        return "User: {$this->email}";
    }
}

📚 Activity Grouping / Batch Support

Automatically group activities from a single job or request. Use the View Batch action in the Activity Log table to inspect all related activities.

  • Spatie v4: Uses the native batch_uuid column for grouping.
  • Spatie v5: Uses custom-property grouping (properties['group']), since upstream batch support was removed in v5. The plugin handles this automatically via the SetActivityContextTap.

🛡️ Audit Risk Scoring

Every activity can receive a configurable risk score based on event type, log name, changed fields, and captured context. The resource displays a risk badge so administrators can quickly notice destructive, security-sensitive, or privacy-sensitive actions.

'risk' => [
    'enabled' => true,
    'events' => [
        'deleted' => 45,
        'force_deleted' => 70,
    ],
    'log_names' => [
        'security' => 35,
        'permissions' => 40,
    ],
],

For advanced applications, provide a custom resolver class in risk.resolver and implement your own score($activity): int logic.

🔒 Privacy-Safe Redaction

Sensitive values are redacted by default before they appear in changes, raw properties, action helper text, and future export workflows.

'privacy' => [
    'redacted_value' => '[redacted]',
    'redaction' => [
        'enabled' => true,
        'fields' => ['password', 'token', 'api_key', 'secret'],
    ],
],

This keeps audit screens useful while reducing the chance that administrators accidentally expose credentials or secrets.

🏛️ Immutable Audit Mode

For stricter environments, enable immutable mode to hide destructive panel actions like delete, prune, restore, and revert:

'privacy' => [
    'immutable_mode' => true,
],

⚙️ Configuration

You can customize almost every aspect of the package via the filament-activity-log.php config file.

Customizing Table Columns

'table' => [
    'columns' => [
        'log_name' => [
            'visible' => true,
            'searchable' => true,
            'sortable' => true,
        ],
        // ...
    ],
],

Customizing Widgets

'widgets' => [
    'widgets' => [
        \AlizHarb\ActivityLog\Widgets\ActivityChartWidget::class,
        \AlizHarb\ActivityLog\Widgets\LatestActivityWidget::class,
    ],
    'activity_chart' => [
        'enabled' => true,
        'days' => 30,
        'fill_color' => 'rgba(16, 185, 129, 0.1)',
        'border_color' => '#10b981',
    ],
    'latest_activity' => [
        'enabled' => true,
        'limit' => 10,
    ],
],

Custom Authorization

Restrict access to specific users by implementing a custom authorizer invokable class:

// app/Authorizer/ActivityLogAuthorizer.php
namespace App\Authorizer;

class ActivityLogAuthorizer
{
    public function __invoke(User $user): bool
    {
        // Define your custom logic to determine if the user can access the activity log.
        return $user->id === 1;
    }
}

Then register it in the config:

// config/filament-activity-log.php
'permissions' => [
    'custom_authorization' => \App\Authorizer\ActivityLogAuthorizer::class,
],

Advanced Documentation

🤝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

Development Setup

# Clone repository
git clone https://github.com/alizharb/filament-activity-log.git

# Install dependencies
composer install

# Run tests
composer test

# Format code
composer format

💖 Sponsor This Project

If this package helps you, consider sponsoring its development:

Sponsor on GitHub

Your support helps maintain and improve this package! 🙏

🐛 Issues & Support

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

alizharb/filament-activity-log 适用场景与选型建议

alizharb/filament-activity-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 77.04k 次下载、GitHub Stars 达 28, 最近一次更新时间为 2025 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「timeline」 「laravel」 「spatie」 「audit-trail」 「activity-log」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 alizharb/filament-activity-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alizharb/filament-activity-log 我们能提供哪些服务?
定制开发 / 二次开发

基于 alizharb/filament-activity-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-02