Laravel Activitylog

Records and queries a full audit trail of activity inside your Laravel application

Library
Composer
v5.1.0
5,890stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
81/100Excellent
Development Activity72
Maintenance72
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture82
Code Quality84
Innovation70
Learning Curve85

Laravel Activitylog by Spatie logs meaningful events that happen in a Laravel application — model changes, custom events, and user actions — to a database table that can be queried like any other Eloquent model. It ships an Activity model, a LogsActivity trait for Eloquent models, and a fluent activity() helper for logging arbitrary events.

With the trait applied, the package automatically records create/update/delete changes on a model, including old and new attribute values, and associates each log entry with a causer (typically the authenticated user) and an optional subject. This gives applications a queryable audit trail without hand-rolling event listeners or a bespoke logging table.

What You Get

  • A LogsActivity trait that auto-logs Eloquent model create/update/delete events with before/after attribute diffs
  • A fluent activity()/ActivityLogger API for logging custom, non-model events
  • An Activity Eloquent model with causer/subject relations for querying who did what to which record
  • Configurable log names, per-attribute logging rules, and event descriptions
  • Artisan commands for cleaning up old log entries past a retention period

Common Use Cases

  • Building an admin-facing audit trail showing who changed what and when on key models
  • Compliance logging for regulated applications that must retain a history of data changes
  • Debugging support tickets by reconstructing the sequence of changes to a customer’s record
  • Logging custom business events (e.g. ‘invoice sent’, ‘subscription cancelled’) alongside model changes

Under The Hood

Architecture - ActivitylogServiceProvider binds a config-driven Activity model and registers the LogsActivity trait’s model-observer hooks (created/updated/deleted) so any Eloquent model that uses the trait gets logged transparently; a separate ActivityLogger/activity() facade path handles ad-hoc, non-model event logging through the same underlying Activity writer. Log entries are persisted to a migration-generated activity_log table with polymorphic subject/causer columns, keeping the audit trail queryable via normal Eloquent relations. Tech Stack - Laravel-only PHP package (illuminate/* contracts, no external services), using a standard Laravel migration/model/trait/facade structure; retention cleanup runs through a scheduled Artisan command rather than a queue worker. Code Quality - 26 test files cover model-change logging, attribute diffing, causer/subject resolution, and log cleanup; the package has shipped 100 tagged releases over nearly a decade, indicating sustained, incremental maintenance rather than large rewrites. API Design - Adoption is a one-line use LogsActivity; on a model plus an optional getActivitylogOptions() override for fine-grained control (which attributes to log, custom descriptions), and the activity()->log() helper mirrors Laravel’s own facade-style ergonomics, keeping the learning curve low for teams already familiar with Eloquent.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search