daimos/entity-changes-fetcher
Small PHP service that detects and reports changes made to an entity by comparing values before and after updates. Useful for auditing, logging, change tracking, and syncing—returns a structured list of modified fields and their old/new values.
updated_at timestamps or third-party audit packages (e.g., laravel-auditlog).EntityChanged) for downstream processing.readme lacks examples, API details, or migration guidance. Assumptions about usage may lead to misconfiguration.User) may need optimization (e.g., batching diffs).updated_at + custom logging.spatie/laravel-activitylog (more features but heavier).jsonb diffs?saving, updating, or deleting events.User, Order) to validate behavior.// app/Observers/ChangeObserver.php
use Daimos\EntityChangesFetcher;
class ChangeObserver {
public function saving($model) {
if ($model instanceof YourModel) {
$diff = EntityChangesFetcher::getChanges($model->getOriginal(), $model->getAttributes());
// Store/process $diff
}
}
}
EntityChanged) to decouple logging from models:
event(new EntityChanged($model, $diff));
changes table (add migration):
Schema::create('changes', function (Blueprint $table) {
$table->id();
$table->string('entity_type');
$table->unsignedBigInteger('entity_id');
$table->json('diff');
$table->timestamps();
});
/changes/{model}/{id}) or admin panels.$model->getChanges() to exclude mass-assigned but unchanged fields.hasMany). May require custom logic.deleted_at.admin_email on User updates).getOriginal() not capturing initial state (e.g., in creating events).dd($model->getChanges()) to inspect diffs.LogEntry). Mitigate with:
changes table size. Archive old diffs or use partitioning.How can I help you explore Laravel packages today?