Add the Activity Log package
This adds hypervel/activity-log, an optional package for recording application activity in a database. An entry can describe an action, the model it affected, who performed it, and any properties the application wants to keep.
activity('billing')
->performedOn($invoice)
->causedBy($user)
->event('paid')
->log('Invoice paid');
Models can also use LogsActivity to record Eloquent events. The model chooses which attributes to log and whether to keep only changes. By default, the logger reads the model as it was at the event. Applications that need database-generated values can opt into a refresh inside the writing transaction.
Persistence
Activities are saved immediately by default. Applications can opt into buffering to insert rows in batches. Each coroutine owns its buffer and its current causer. For an activity recorded on a connection with an open transaction, a rollback discards the buffered entry. After commit, a later batch writes it. Applications that need the activity and the domain change to commit together can use immediate writes on the same connection.
Installation and use
Composer discovers the service provider. The application publishes the migration before running it, so it can choose the appropriate morph keys and indexes. The package includes a cleanup command with configurable retention and optional scheduling. The guide covers installation, querying, model events, transaction behavior, and differences from Spatie’s Laravel Activity Log.
Verification
The package tests cover model changes, causer resolution, coroutine isolation, buffer flushing, and rollback. The migration and row-locking tests ran against MySQL, MariaDB, and PostgreSQL. A clean application installed the split package, published and ran the migration, and recorded an activity through the helper.
Summary by cubic
Adds hypervel/activity-log, an optional package for recording application activity in a database. Activities log an action, the affected model, who performed it, and arbitrary properties through a helper or automatic model event logging.
Persistence
- Activities save immediately by default; applications can opt into coroutine-scoped buffering that flushes rows in bounded batches at lifecycle boundaries.
- Buffered inserts bind to the activity's connection, preserve call order across savepoints, and prepare timestamps on the activity snapshot so custom insert hooks choose the final columns; a rollback on an open transaction discards buffered entries.
- Automatic model logging reads the model's in-memory snapshot;
refreshBeforeLogging()opts into a refresh inside the writing transaction, and restores are logged separately from updates. - Selected JSON columns and parent paths survive child selectors, and selected values are read on the owning model through its cast serializer so enum collections audit by case name and unrelated updates stay out of the log.
Safety and installation
- Partially selected models can no longer resolve an unresolved morph relation against the source table, and unknown morph targets stay out of the change audit.
- Composer discovers the service provider and conflicts with
spatie/laravel-activitylog; applications publish the migration to choose morph keys and indexes, and the package ships a cleanup command with configurable retention. - Tests cover model changes, causer resolution, coroutine isolation, buffer flushing, and rollback; migration and row-locking tests ran on MySQL, MariaDB, and PostgreSQL.
[!NOTE]
Add the Hypervel Activity Log package with model, logger, buffering, and cleanup
Introduces a new hypervel/activity-log package that records model events and manual activity to an activity_log table. It is modeled after spatie/laravel-activitylog and conflicts with that package in Composer.
- Adds the
Activity Eloquent model with subject/causer morph relations and query scopes (inLog, causedBy, forSubject, forEvent), plus the LogsActivity, CausesActivity, and HasActivity model concerns and the activity() helper and facade.
- Adds
LogActivityAction (description placeholders, subject hooks, before-logging callbacks) and CleanActivityLogAction (batched deletion older than a retention cutoff) with an activity-log:clean console command and scheduled cleanup.
- Adds coroutine-scoped
ActivityBuffer for transaction-aware activity buffering, flushed at application termination and after non-sync job attempts.
- Includes a publishable migration, configuration file, and full documentation in activity-log.md.
- Also changes core Eloquent:
MorphTo relations built before the morph type is known now return as eager-loading placeholders (no query, default value returned) in MorphTo.php, and SoftDeletes exposes an is-restoring flag in SoftDeletes.php.
- Risk: the package declares a Composer conflict with
spatie/laravel-activitylog, so projects using that package cannot install both. The MorphTo placeholder change alters morphTo behavior when the morph type attribute is missing — see HasRelationships.php.
Macroscope summarized 68ab5cf.