spatie/laravel-activitylog
Log user and model activity in Laravel with an easy API. Manually record actions or automatically log Eloquent events, attach subjects/causers and custom properties, and query everything via the Activity model stored in the activity_log table.
performedOn(), causedBy(), etc.) for filtering logs, which is useful for dashboards or admin panels.created, updated, deleted).withinBatch()) for bulk operations and configure cleanup jobs to prune old logs.activity_log table requires a migration, and customizations (e.g., UUIDs) may introduce edge cases.withProperties() judiciously and test with edge-case data.activity()->log())?causer or custom properties)?User or Order) to test logging behavior.activity()->log()) before enabling automatic events.Activity::cleanup() via cron).composer.json.MorphableId or String for subject_id/causer_id.activity_log table via migration or use withProperties().composer require spatie/laravel-activitylog.php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider".php artisan migrate.config/activitylog.php (e.g., log retention, table name).php artisan schedule:run
Add to app/Console/Kernel.php:
$schedule->command(ActivityCleanupCommand::class)->daily();
activity()->log().use Spatie\Activitylog\Traits\LogsActivity;
class User extends Model { use LogsActivity; }
logOnly() or logExcept() to fine-tune events:
class User extends Model {
use LogsActivity;
protected $logOnly = ['name', 'email'];
}
Activity::cleanup() or custom queries to archive old logs.activity_log fields) to avoid merge conflicts during updates.unguard() if needed).Activity::latest()->toSql() to inspect queries.tapActivity() to inspect log objects before saving.activity()->log() with a queue job).activity()->log('User updated')->viaQueue();
How can I help you explore Laravel packages today?