webgefaehrten/laravel-auto-notes
Composer 安装命令:
composer require webgefaehrten/laravel-auto-notes
包简介
Polymorphic notes package for Laravel models with owner support, field diffs, retention, and multi-language support.
README 文档
README
Polymorphe Notizen für Laravel-Modelle mit optionalem Owner (Aggregation), automatischen Diffs (Feldänderungen), In-Class-Konfiguration, Retention/Pruning, optionalem Owner-Index und Mehrsprachigkeit (DE/EN).
🇩🇪 Deutsch
✨ Features
- Automatische Notizen bei
created,updated,deleted - Feld-Diffs: von
X→Y - Owner/Aggregation: z. B. Kunde ↔ Baustellen ↔ Kontakte
- In-Class-Konfiguration (kein zentrales Config-File nötig)
- Manuelles Hinzufügen von Notizen (
addNote()) - Observer pro Model deaktivierbar oder austauschbar
- Retention & Archivierung (alte Notizen löschen oder verschieben)
- Optionaler Owner-Index für schnelle Abfragen
- Mehrsprachigkeit (DE/EN) mit Publish-Option
🚀 Installation
composer require webgefaehrten/laravel-auto-notes
Publizieren:
php artisan vendor:publish --provider="Webgefaehrten\AutoNotes\AutoNotesServiceProvider" --tag=auto-notes-config php artisan vendor:publish --provider="Webgefaehrten\AutoNotes\AutoNotesServiceProvider" --tag=auto-notes-migrations php artisan vendor:publish --provider="Webgefaehrten\AutoNotes\AutoNotesServiceProvider" --tag=auto-notes-lang
Migrationen ausführen:
php artisan migrate
🛠 Verwendung
Subject-Model (z. B. CustomerSite):
use Webgefaehrten\AutoNotes\Traits\HasNotes; use Webgefaehrten\AutoNotes\Contracts\ProvidesAutoNotesConfig; use Illuminate\Database\Eloquent\Model; class CustomerSite extends Model implements ProvidesAutoNotesConfig { use HasNotes; protected $fillable = ['customer_id','name','street','zip','city']; public function customer() { return $this->belongsTo(Customer::class); } // In-Class Konfiguration public function autoNoteContext(): ?string { return 'site'; } public function autoNoteLabels(): array { return ['name'=>'Name','city'=>'Ort']; } public function autoNoteInclude(): array { return ['name','city','zip','street']; } // Variante 1: direkte Relation (funktioniert, wenn Relation verfügbar ist) public function autoNoteOwner(): ?Model { return $this->customer; } // Variante 2: robuste Variante (nur Klasse zurückgeben, FK wird automatisch erkannt) public function autoNoteOwner(): Model|string|array|\Closure|null { return \App\Models\Customer::class; } public function autoNoteOwnerKey(): ?string { return 'customer_id'; // optional } public function autoNoteDisplayName(): ?string { return $this->name; } }
Owner-Model (z. B. Customer):
use Webgefaehrten\AutoNotes\Traits\AggregatesNotes; class Customer extends Model { use AggregatesNotes; // ->allNotes() }
Manuell Notiz anlegen:
$site->addNote( title: 'Adresse geändert', body: 'Von A-Straße nach B-Straße', context: 'site', owner: $site->customer );
Alle Notizen abrufen:
$notes = $customer->allNotes; // alle Notizen des Customers $notes = $site->notes; // nur Notizen der Site
⚙️ Retention / Archivierung
Konfiguration in config/auto-notes.php:
'retention_days' => 730, 'retention_overrides' => [ 'order' => 1825, // 5 Jahre für Aufträge ], 'archive_to_table' => 'notes_archive',
Prune-Command:
php artisan auto-notes:prune
🌍 Mehrsprachigkeit
php artisan vendor:publish --tag=auto-notes-lang
Verfügbare Sprachen: de, en.
🇬🇧 English
✨ Features
- Automatic notes on
created,updated,deleted - Field diffs: from
X→Y - Owner/Aggregation: e.g. Customer ↔ Sites ↔ Contacts
- In-class configuration (no central config file required)
- Add notes manually (
addNote()) - Observer per model can be disabled or replaced
- Retention & pruning (delete/archive old notes)
- Optional owner index for fast queries
- Multi-language (EN/DE) with publish option
🚀 Installation
composer require webgefaehrten/laravel-auto-notes
Publish:
php artisan vendor:publish --provider="Webgefaehrten\AutoNotes\AutoNotesServiceProvider" --tag=auto-notes-config php artisan vendor:publish --provider="Webgefaehrten\AutoNotes\AutoNotesServiceProvider" --tag=auto-notes-migrations php artisan vendor:publish --provider="Webgefaehrten\AutoNotes\AutoNotesServiceProvider" --tag=auto-notes-lang
Run migrations:
php artisan migrate
🛠 Usage
Subject model (e.g. CustomerSite):
use Webgefaehrten\AutoNotes\Traits\HasNotes; use Webgefaehrten\AutoNotes\Contracts\ProvidesAutoNotesConfig; use Illuminate\Database\Eloquent\Model; class CustomerSite extends Model implements ProvidesAutoNotesConfig { use HasNotes; protected $fillable = ['customer_id','name','street','zip','city']; public function customer() { return $this->belongsTo(Customer::class); } public function autoNoteContext(): ?string { return 'site'; } public function autoNoteLabels(): array { return ['name'=>'Name','city'=>'City']; } public function autoNoteInclude(): array { return ['name','city','zip','street']; } // Variant 1: direct relation public function autoNoteOwner(): ?Model { return $this->customer; } // Variant 2: more robust (only return class, FK auto-resolved) public function autoNoteOwner(): Model|string|array|\Closure|null { return \App\Models\Customer::class; } public function autoNoteOwnerKey(): ?string { return 'customer_id'; // optional } public function autoNoteDisplayName(): ?string { return $this->name; } }
Owner model (e.g. Customer):
use Webgefaehrten\AutoNotes\Traits\AggregatesNotes; class Customer extends Model { use AggregatesNotes; // ->allNotes() }
Add note manually:
$site->addNote( title: 'Address changed', body: 'From A-Street to B-Street', context: 'site', owner: $site->customer );
Fetch notes:
$notes = $customer->allNotes; // all notes of the customer $notes = $site->notes; // only notes of the site
⚙️ Retention / Archiving
Config in config/auto-notes.php:
'retention_days' => 730, 'retention_overrides' => [ 'order' => 1825, // 5 years for orders ], 'archive_to_table' => 'notes_archive',
Prune command:
php artisan auto-notes:prune
🌍 Multi-language
php artisan vendor:publish --tag=auto-notes-lang
Available languages: en, de.
ℹ️ Owner Resolution
-
autoNoteOwner()may return:- a
Model - a
class-string(e.g.Customer::class) - an array
[Customer::class, $id] - a
Closurereturning aModel - or
null
- a
-
Optional methods:
autoNoteOwnerKey()→ explicit FK nameautoNoteOwnerRelation()→ explicit relation name
Default heuristics: customer_id → owner_id → {ClassSnake}_id → relation.
webgefaehrten/laravel-auto-notes 适用场景与选型建议
webgefaehrten/laravel-auto-notes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「timeline」 「observer」 「laravel」 「activity」 「history」 「notes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webgefaehrten/laravel-auto-notes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webgefaehrten/laravel-auto-notes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webgefaehrten/laravel-auto-notes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add timelines to custom pages or infolist entries effortlessly. Plus, it teams up smoothly with Spatie Activitylog for easy tracking.
A collection of observer classes that can be use in your Laravel application.
Logs information about scheduler task execution and displays them in a graphical timeline
Event dispatcher package
Bundle extension that installs and loads Semantic MediaWiki and associated extensions
Enables a new content element of type Timeline
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-10