Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Activitylog Laravel Package

rmsramos/activitylog

A Laravel package for logging user and model activity to the database. It provides traits and helpers to record who changed what and when, then query activities to build audit trails, dashboards, and activity feeds with customizable models and a clean API.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install the package via Composer: composer require rmsramos/activitylog. This package is a Filament plugin that provides a UI for spatie/laravel-activitylog. Ensure you have Filament (v3+) and Spatie’s activitylog installed and migrated.
  • Publish the config file: php artisan vendor:publish --tag="activitylog-config". Review config/activitylog.php to set navigation labels, permissions, and whether to enable restore actions.
  • Register the plugin in your Filament panel provider: ->plugin(ActivitylogPlugin::make()). This adds an “Activity Log” resource to your admin panel where you can browse, filter, and inspect all logged activities.
  • First use case: add Spatie’s LogsActivity trait to a model (e.g., Order). Perform some actions, then open the Activity Log resource in Filament to see the entries. You can filter by subject, causer, event, and date. For a specific record, add the provided relation manager (ActivitylogRelationManager) to your resource to show its activity history inline.

Implementation Patterns

  • Per‑model activity history: Attach ActivitylogRelationManager to any Filament resource to display a table of activities for that record. This is the most common day‑to‑day pattern—reviewing changes to a single order, user, or product without leaving the edit page.
  • Restore soft‑deleted records: The package exposes restore actions on activity log entries for soft‑deletable subjects. When restoring, it calls withoutLogging() and withChanges() if available (Spatie v5), so the restore itself isn’t logged and the original attribute changes are preserved. Use this as an “undo” mechanism directly from the log.
  • Attribute diffs: For Spatie v5, diffs are read from attribute_changes; for older v4 logs it falls back to properties.old / properties.attributes. This means you can upgrade Spatie without losing the ability to view historical diffs, but new logs will use the v5 format.
  • Customising the resource: Extend the provided ActivitylogResource or publish the views to tailor columns, filters, and actions. You can also override the Activity model if you need extra scopes or accessors.
  • Integration with existing logging: Use Spatie’s LogsActivity trait with custom getActivitylogOptions() to control which attributes are logged and how events are described. The package renders whatever Spatie stores, so your logging configuration directly shapes the UI.

Gotchas and Tips

  • Spatie v5 migration is mandatory: The package supports v5, but you must run Spatie’s own migration to add the attribute_changes column and drop batch_uuid. Without it, new logs won’t have the expected column and diffs may not render. Follow Spatie’s UPGRADING guide.
  • Config key rename: In Spatie v5, subject_returns_soft_deleted_models becomes include_soft_deleted_subjects. Update your config/activitylog.php accordingly; the package relies on this for restore actions.
  • Restore actions and logging: The package uses withoutLogging() and withChanges() only when those methods exist (v5). On v4, the fallback restores without these safeguards, so test restore behaviour after upgrading.
  • Large log tables: Activity logs grow quickly. Schedule Spatie’s activitylog:clean command and consider adding indexes on subject_type, subject_id, and created_at for performance.
  • Permissions: The resource respects Filament’s authorization. If users can’t see the Activity Log, check policies and the viewAny ability on the Activity model.
  • Debugging missing logs: Ensure the model uses LogsActivity, that log_name matches any filters, and that the Activity model is correctly configured in config/activitylog.php. The package’s resource uses the default Spatie\Activitylog\Models\Activity unless overridden.
  • Extension points: Publish the package’s views (--tag="activitylog-views") to customise the table and infolist. You can also bind a custom ActivitylogResource in your panel if you need deeper changes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core