定制 egough/holocron 二次开发

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

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

egough/holocron

Composer 安装命令:

composer require egough/holocron

包简介

A Laravel package for recording and querying historical events across your application.

README 文档

README

Holocron

Latest Version on Packagist Total Downloads License Tests

Polymorphic history recording and activity timeline for Laravel.

Combines audit-style field diffing with human-readable event logging — so you can track both low-level attribute changes and meaningful business events in a single, consistent history record.

Quick Example

// Record a manual event
Holocron::record('status_changed')
    ->on($order)
    ->by(auth()->user())
    ->message('Order marked as paid')
    ->withMeta(['from' => 'pending', 'to' => 'paid'])
    ->save();

// Automatic tracking via model trait
class Order extends Model
{
    use HasHistory;

    protected array $holocronTrack = ['status', 'total'];
}

// Query the timeline
$order->history()->latest('recorded_at')->get();
$order->holocronTimeline();

When Should I Use This Package?

Use Holocron when your application needs a persistent, queryable record of what happened, who did it, and what changed.

Typical use cases:

  • Order or payment lifecycle tracking
  • Content moderation and editorial history
  • Support ticket and case notes
  • User account activity logs
  • Audit trails for compliance

When Not to Use It

Holocron is not a debugging or error-tracking tool. For application exceptions and performance monitoring, consider something like Flare or Sentry.

If you only need simple model diffing without human-readable events, a lightweight audit package may be a better fit. Holocron is designed for applications where both matter.

Installation

composer require egough/holocron

Publish the config and migrations:

php artisan vendor:publish --tag=holocron-config
php artisan vendor:publish --tag=holocron-migrations
php artisan migrate

Manual Recording

Use the Holocron facade or helper to record events anywhere in your application.

use Egough\Holocron\Facades\Holocron;

Holocron::record('note_added')
    ->on($ticket)
    ->by(auth()->user())
    ->message('Support note added by agent')
    ->category('communication')
    ->save();

Record explicit attribute diffs:

Holocron::record('updated')
    ->on($post)
    ->by($user)
    ->withChanges([
        'title' => ['old' => 'Old Title', 'new' => 'New Title'],
    ])
    ->message('Post title updated')
    ->save();

Attach arbitrary metadata:

Holocron::record('invoice_resent')
    ->on($invoice)
    ->by($user)
    ->withMeta(['recipient' => 'billing@example.com'])
    ->save();

Model Integration

Add the HasHistory trait to any Eloquent model to enable automatic and on-demand history recording.

use Egough\Holocron\Concerns\HasHistory;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    use HasHistory;

    protected array $holocronTrack = ['status', 'total'];
}

Automatic Events

The trait automatically records created, updated, deleted, and restored events. For updates, tracked field diffs are stored as:

{
  "status": {
    "old": "draft",
    "new": "active"
  }
}

Control which events are recorded per model:

protected array $holocronEvents = ['created', 'deleted'];

Querying History

$order->history;

$order->history()->latest('recorded_at')->get();

$order->latestHistory()->get();

$order->holocronTimeline();

Recording from the Model

$project->recordHistory(
    event: 'archived',
    message: 'Project archived by admin',
    actor: auth()->user(),
);

Querying

The HolocronEntry model includes helpful query scopes.

use Egough\Holocron\Models\HolocronEntry;

// Filter by subject and event type
HolocronEntry::query()
    ->forSubject($order)
    ->event('status_changed')
    ->latest('recorded_at')
    ->get();

// Filter by actor and category
HolocronEntry::query()
    ->causedBy($user)
    ->category('communication')
    ->get();

Configuration

The published config file gives you control over table naming, automatic event recording, excluded attributes, and actor resolution.

return [
    'table_name' => 'holocron_entries',

    'auto_record' => [
        'created'  => true,
        'updated'  => true,
        'deleted'  => true,
        'restored' => true,
    ],

    'exclude' => [
        'created_at',
        'updated_at',
    ],

    'actor_resolver' => static fn () => auth()->user(),
];

Testing

Install development dependencies:

composer install

Run the test suite:

composer test

Or run PHPUnit directly:

vendor/bin/phpunit

Tests use an in-memory SQLite setup — no external database required.

Requirements

  • PHP 8.2+
  • Laravel 11, 12, or 13

License

MIT

egough/holocron 适用场景与选型建议

egough/holocron 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 148 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 egough/holocron 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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