定制 getimmutable/laravel 二次开发

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

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

getimmutable/laravel

Composer 安装命令:

composer require getimmutable/laravel

包简介

Laravel SDK for the Immutable audit log API.

README 文档

README

Laravel SDK for the Immutable audit log API.

Installation

composer require getimmutable/laravel

The package auto-discovers its service provider. Publish the config file:

php artisan vendor:publish --tag=getimmutable-config

Configuration

Add the following to your .env file:

GETIMMUTABLE_API_KEY=your-api-key
GETIMMUTABLE_BASE_URL=https://api.getimmutable.com
GETIMMUTABLE_ASYNC=true
Variable Default Description
GETIMMUTABLE_API_KEY Your Immutable API key
GETIMMUTABLE_BASE_URL https://api.getimmutable.com API base URL
GETIMMUTABLE_ASYNC true Dispatch events via queue job

Queue Configuration

Important: Async mode (the default) dispatches events to the getimmutable queue. If your queue worker is not processing this queue, events will silently sit in the queue and never be sent.

Make sure your queue worker includes the getimmutable queue:

php artisan queue:work --queue=getimmutable,default

Or if you use Laravel Horizon, add a supervisor entry in config/horizon.php:

'environments' => [
    'production' => [
        'supervisor-getimmutable' => [
            'connection' => 'redis',
            'queue' => ['getimmutable'],
            'minProcesses' => 1,
            'maxProcesses' => 3,
            'balanceMaxShift' => 1,
            'balanceCooldown' => 3,
            'tries' => 3,
        ],
    ],
],

For local development or testing, set GETIMMUTABLE_ASYNC=false to send events synchronously (no queue required).

Usage

Raw Payload

use GetImmutable\AuditLog;

AuditLog::track([
    'actor_id' => 'usr_123',
    'action' => 'project.created',
    'resource' => 'Project',
    'resource_id' => 'prj_456',
    'metadata' => ['ip' => request()->ip()],
]);

Fluent Builder (from Auth)

use GetImmutable\AuditLog;

// Uses the currently authenticated user as the actor
AuditLog::fromAuth()->track('project.created', $project, [
    'ip' => request()->ip(),
]);

Fluent Builder (explicit Actor)

use GetImmutable\AuditLog;

AuditLog::actor($user)->track('invoice.paid', $invoice, [
    'amount' => 9900,
]);

Resource Handling

The track() method on the builder accepts three resource types:

  • Eloquent Model — auto-extracts resource, resource_id, and resource_name (via optional getAuditName() method)
  • String — treated as the resource type name (e.g. 'Project')
  • null — no resource fields are included
// Eloquent model
AuditLog::fromAuth()->track('project.deleted', $project);

// Plain string
AuditLog::fromAuth()->track('report.exported', 'Report');

// No resource
AuditLog::fromAuth()->track('user.logged_in');

Batch Events

use GetImmutable\AuditLog;

AuditLog::trackBatch([
    ['actor_id' => 'usr_1', 'action' => 'item.created'],
    ['actor_id' => 'usr_2', 'action' => 'item.updated'],
]);

Automatic Eloquent Tracking

Add the TracksEvents trait to any Eloquent model to automatically track created, updated, and deleted events:

use GetImmutable\Concerns\TracksEvents;
use Illuminate\Database\Eloquent\Model;

class Project extends Model
{
    use TracksEvents;
}

Customize which events to track:

class Project extends Model
{
    use TracksEvents;

    protected static array $trackedEvents = ['created', 'deleted'];
}

Events are recorded as project.created, project.updated, project.deleted (lowercased model name + event).

Testing

In your test suite, you can either:

  1. Set GETIMMUTABLE_ASYNC=false and use Http::fake() to intercept API calls
  2. Set GETIMMUTABLE_ASYNC=true and use Queue::fake() to assert jobs were dispatched
use GetImmutable\AuditLog;
use GetImmutable\Jobs\SendAuditLogEvent;
use Illuminate\Support\Facades\Queue;

Queue::fake();

AuditLog::track(['actor_id' => 'test', 'action' => 'test.action']);

Queue::assertPushed(SendAuditLogEvent::class);

getimmutable/laravel 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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