spatie/laravel-activitylog
73.0
Strong · 19 September 2026
1.5k
lines of production code
PHP
primary language
1
measurement over time
What this system is
This system is a Laravel package that provides comprehensive activity logging for Eloquent models, tracking creation, updates, deletions, and restorations. It captures attribute changes and polymorphic relationships between causers and subjects, supporting both manual and automatic logging via traits. The package includes features for buffering logs for performance, cleaning old records, and filtering activities by type or event using type-safe enums.
How it got here
2016 — Version 5 major release
7 changes.
This period focused on the major v5 release, upgrading the package to require PHP 8.4 and Laravel 12+ while modernizing the API and database schema. Key changes included replacing the skeleton scaffolding with a full service provider, introducing a new configuration file, and adding specific exception classes and event-based filtering for activity logs.
2018–2026 — Activity logging architecture modernization
5 changes.
This period focused on modernizing the activity logging system by introducing a standardized contract, a fluent facade-based API, and dedicated action classes for logging and cleanup. The implementation was updated to support PHP 8.4+ and Laravel 11+, incorporating type-safe enums, batching capabilities, and a builder pattern for constructing activity logs.
Features
Added activity\_log table migration stub
A new migration stub file has been added to the database/migrations directory to define the schema for the 'activity\_log' table. This stub creates the table with columns for ID, log name, description, subject and causer polymorphic relationships, event type, JSON attributes and properties, and timestamps, providing the necessary database structure for the package's activity logging feature.
database · high confidence
Initial configuration file for Activity Log package
The package now provides a \config/activitylog.php\ file that allows users to customize activity logging behavior. Key configurable options include enabling or disabling logging, setting the number of days to retain logs (\clean\_after\_days\), defining the default log name, specifying a custom authentication driver, and toggling the inclusion of soft-deleted subjects. Users can also configure the activity model class, set default attributes to exclude from logs, enable a memory buffer for bulk logging to improve performance under high load, and override the default action classes for logging and cleaning.
config · high confidence
Introduces Activity contract for activity log models
A new \Activity\ interface has been added to the contracts layer, defining the required methods for activity log models. This contract specifies that implementing classes must provide \subject()\ and \causer()\ relationships (returning \MorphTo\) and a \getProperty()\ method to retrieve specific property values with an optional default. This standardizes the API for interacting with activity log entries across the application.
src/Contracts · high confidence
New Activity facade for fluent activity logging
A new \Activity\ facade has been added to the library, providing a static interface for the \PendingActivityLog\ service. This allows users to fluently construct and log activities using method chaining (e.g., \Activity::causedBy($user)-\>log('Updated profile')\) without needing to manually resolve the underlying service from the container. The facade is configured to bypass caching (\$cached = false\) to ensure that the builder instance remains fresh for each call, supporting the fluent API pattern.
src/Facades · high confidence
Behavioural changes
Activity logging now uses an explicit event type and supports BackedEnum log names
The Activity model now includes an \event\ column and a \scopeForEvent\ query scope, allowing users to filter activity logs by specific event types (e.g., created, updated, deleted) rather than relying solely on the description. Additionally, the \scopeInLog\ filter now accepts \BackedEnum\ values for log names, enabling type-safe filtering using the new \ActivityEvent\ enum. The \LogsActivity\ trait has been updated to automatically set this event type based on the model's lifecycle events, and the \CausesActivity\ and \HasActivity\ traits provide standardized relationships for accessing these logs.
src/Models · high confidence
Introduction of specific exception classes for configuration and logging errors
The library now provides dedicated exception classes to handle specific error scenarios during activity logging. An \InvalidConfiguration\ exception has been added to signal issues when a provided model class does not implement the required \Activity\ contract or extend the \Model\ base class, or when an action class does not extend the expected base class. Additionally, a \CouldNotLogActivity\ exception has been introduced to handle cases where a user cannot be determined by a given identifier, replacing the previous placeholder test scaffolding.
src/Exceptions · high confidence
Modernized activity logging with BackedEnum support and new support classes
The \src/Support\ directory has been completely rewritten to support PHP 8.4+ and Laravel 11+. This update introduces several new support classes: \ActivityBuffer\ for batching activity inserts, \ActivityLogStatus\ for managing logging enable/disable states, \ActivityLogger\ as the fluent logging interface, \CauserResolver\ for resolving the user who triggered an activity, \ChangeDetector\ for identifying attribute changes, \Config\ for resolving activity models and actions, \LogOptions\ for configuring model-level logging behavior, and \PendingActivityLog\ for chaining logging operations. A key behavioral change is the addition of BackedEnum support for log names and events in \ActivityLogger\ and \LogOptions\, allowing users to pass enum instances (e.g., \ActivityEvent::updated\) instead of strings. The \ActivityLogger\ now uses a builder pattern with methods like \performedOn()\, \causedBy()\, \event()\, and \withChanges()\ to construct activity logs.
src/Support · high confidence
Modernized activity logging with action classes and enum-based events
The activity logging system has been refactored to use dedicated action classes (\LogActivityAction\, \CleanActivityLogAction\) for handling logging and cleanup logic, allowing users to customize behavior by extending these classes or swapping them via configuration. Event types are now represented by the \ActivityEvent\ enum (\Created\, \Updated\, \Deleted\, \Restored\), providing a type-safe way to query and filter activities. A new artisan command \activitylog:clean\ has been added to remove old records based on age, configurable via the \clean\_after\_days\ setting. These changes modernize the internal architecture while maintaining backward compatibility for existing usage patterns.
(repo-wide) · high confidence
Replaces skeleton template with Laravel Activitylog service provider and helper
The skeleton package scaffolding (SkeletonClass, SkeletonFacade, and SkeletonServiceProvider) has been removed and replaced by the actual Laravel Activitylog implementation. The new ActivitylogServiceProvider registers the activity logger as a bound instance and scopes the CauserResolver, ActivityLogStatus, and ActivityBuffer services to the request lifecycle. It also configures the ActivityBuffer to flush on request termination, after successful/failed queue jobs, and during PHP shutdown when buffering is enabled. A global activity() helper function is provided to create pending activity logs with an optional log name.
src · high confidence
Upgrade to v5 with PHP 8.4+ and Laravel 12+ requirements
The package has been upgraded to version 5, which raises the minimum requirements to PHP 8.4+ and Laravel 12+. This release introduces a modernized API and a new database schema: the \properties\ column now stores only custom user data, while a new \attribute\_changes\ column tracks model changes. The batch system has been removed, and several methods and properties have been renamed (e.g., \getExtraProperty()\ to \getProperty()\, \$activity-\>changes\ to \$activity-\>attribute\_changes\). Configuration keys have also been updated, such as \delete\_records\_older\_than\_days\ to \clean\_after\_days\. Existing users upgrading from v4 must run a migration to adapt their database schema and update their code to reflect the API changes.
(repo-wide) · high confidence
Test coverage
Comprehensive test suite for activity logging functionality
Added a new, extensive test suite covering the core activity logging features. This includes tests for the \Activity\ model scopes (filtering by log, causer, subject, and event), custom activity models (including validation of invalid configurations and custom database connections/tables), and the \ActivityBuffer\ for batched logging. It also covers the \CauserResolver\ for identifying who triggered an activity, the \LogsActivity\ trait for automatic event logging (create, update, delete, soft-delete), and the \DetectsChanges\ trait for capturing attribute diffs, including support for custom casts like \IntervalCasts\ and PHP enums (int, string, and non-backed).
tests · high confidence
Dependencies
Upgrade to Laravel 12/13 and PHP 8.4 with Pest testing
The package now requires PHP 8.4 and supports Laravel 12 and 13, dropping compatibility with older versions. Development tools have been modernized by switching from PHPUnit to Pest for testing, and the testbench dependency has been updated to version 10 or 11 to align with the new Laravel versions.
(dependencies) · high confidence
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Baseline
- First survey — no prior run to compare against. CAI 73.
Lenses
- Code Health 100
- Architecture 96
- Maturity 66
- Readiness 84
- Security 68
Changes since last survey
- 300 commits — 243 feature/other, 57 fixes
By area
- (root) — 76 commits
- (repo) — 72 commits
- .github/workflows — 36 commits
- docs/advanced-usage — 19 commits
- src/Traits — 16 commits
- tests/ActivityLoggerTest.php — 11 commits
- src/ActivityLogger.php — 10 commits
- src/Actions — 7 commits
- src/Models — 7 commits
- src/LogOptions.php — 5 commits
- tests/Models — 4 commits
- config/activitylog.php — 3 commits
- docs/introduction.md — 3 commits
- tests/AbleStoreNonBackedEnumTest.php — 3 commits
- tests/Pest.php — 3 commits
- docs/api — 2 commits
- src/Facades — 2 commits
- src/PendingActivityLog.php — 2 commits
- tests/LogsActivityTest.php — 2 commits
- .github/CONTRIBUTING.md — 1 commit
Notable commits
- fix: Added return type in the example + typo fix.
- fix: FIX migration and config publish tag
- fix: Fix LogOptions closure preventing model serialization in queued listeners (#1453)
- fix: Fix UPGRADING to add tables migration
- fix: Fix setBatch return type
- fix: Fix activitylog cleanup to require integer days input (#1448)
- fix: Fix case if the model is using SoftDeletes trait
- fix: Fix composer.json homepage to point at this repository (#1467)
- fix: Fix for replacePlaceholders with ending dot
- fix: Fix nullable log names (#1029)
- fix: Fix outdated docs subdomain links in requirements (#1466)
- fix: Fix styling
- fix: Fix styling
- fix: Fix styling
- fix: Fix styling
- fix: Fix styling
- fix: Fix styling
- fix: Fix styling
- fix: Fix styling
- fix: Fix styling
- …and 280 more
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
spatie/laravel-activitylog was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 19 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit c37c43b32ea1ff15dc00491c07dafdfb8fd57340 — the exact code this score is about.
- Scored under rubric-2026.09.15 — the same rubric and the same method as every other entry in this index.
- Measured by watchdog.canine.dev using codehealth-analyzer preprod-13a154b7f5d1.