deifhelt/laravel-activity-presenter
Composer 安装命令:
composer require deifhelt/laravel-activity-presenter
包简介
Activity presenter for Laravel.
README 文档
README
Laravel Activity Presenter is a powerful presentation layer for spatie/laravel-activitylog. It solves the common challenges of displaying activity logs in your application: resolving relationships efficiently, formatting data consistently, and handling translations.
Why use this?
When displaying activity logs, you often face these issues:
- N+1 Queries: Showing "User X updated Project Y" requires loading the User and Project models for every log entry.
- Missing Context: If "Project Y" is deleted, you still want to show its name in the log history, but the relationship is null.
- Unformatted Data: You have
user_id: 5in the log properties, but you want to display "John Doe". - Inconsistent Presentation: You find yourself repeating
trans('...')...logic in every Blade view.
This package solves all of them.
Key Features
- Smart Resolution: Automatically resolves related models (User, Subject) in a single optimized query to prevent N+1 issues.
- Object-Oriented: Provides rich objects (
LogEntry,AttributeChange) instead of flat strings, giving you full control in your View. - Config-Driven: Define how specific attributes (like
category_id) map to models in a simple config file. - Auto-Localization: Built-in support for translating events (
created->Creado), model names (User->Usuario), and attributes. - Agnostic & Flexible: Does not force date formats or string styles. You get the raw
Carbonobjects and Models to format however you like.
Installation
Install via Composer (Spatie Activitylog is included automatically):
composer require deifhelt/laravel-activity-presenter
Publish the configuration:
php artisan vendor:publish --provider="Deifhelt\ActivityPresenter\ActivityPresenterServiceProvider"
Quick Usage
1. In your Controller
use Deifhelt\ActivityPresenter\Facades\ActivityPresenter; use Spatie\Activitylog\Models\Activity; public function index() { // Fetch logs (paginated) $activities = Activity::latest()->paginate(20); // Present them (loads relations, formats dates, translates events) $presented = ActivityPresenter::presentCollection($activities); return view('activities.index', [ 'activities' => $presented ]); }
2. In your Blade View
@foreach($activities as $log) <div class="activity-item"> <!-- Full Control over Date Format --> <span class="date">{{ $log->activity->created_at->diffForHumans() }}</span> <!-- "John Doe created Project Alpha" --> <p> @if($log->causer) <a href="{{ route('users.show', $log->causer) }}"> <strong>{{ $log->getCauserLabel() }}</strong> </a> @else System @endif {{ $log->getEventLabel() }} <strong>{{ $log->getSubjectLabel() }}</strong> </p> <!-- Show changes: "Status: Pending -> Active" --> <ul> @foreach($log->changes as $change) <li> {{ $change->key }}: <span class="text-red-500">{{ $change->old }}</span> → <!-- If it's a resolved model (e.g. status_id -> Status Model), link to it! --> @if($change->relatedModel) <a href="{{ route('statuses.show', $change->relatedModel) }}" class="text-green-500"> {{ $change->relatedModel->name }} </a> @else <span class="text-green-500">{{ $change->new }}</span> @endif </li> @endforeach </ul> </div> @endforeach
Documentation
- Installation & Configuration - Deep dive into setup and config options.
- Logging Guide - Best practices for logging model events.
- Usage Patterns - Advanced usage in Controllers, Views, and APIs.
- Localization - How to translate every aspect of your logs.
License
The MIT License (MIT). Please see License File for more information.
deifhelt/laravel-activity-presenter 适用场景与选型建议
deifhelt/laravel-activity-presenter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「laravel」 「activity」 「activitylog」 「activity presenter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 deifhelt/laravel-activity-presenter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 deifhelt/laravel-activity-presenter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 deifhelt/laravel-activity-presenter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
A very simple activity logger to monitor the users of your website or application (for MongoDB)
A simple activity feed for laravel 5+
Laravel activity log viewer
A very simple logger to monitor the users' activities
A very simple activity logger to monitor the users of your website or application
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-01