threls / activity-log
This is my package activity-log
Fund package maintenance!
threls
Installs: 1 816
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/threls/activity-log
Requires
- php: ^8.4
- illuminate/contracts: ^10.0||^11.0||^12.0
- jenssegers/agent: ^2.6
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- dev-main
- 2.0.0
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-log-improvements
- dev-add-description-in-activity-log
- dev-Implement-Interface-to-get-activity-display-name
- dev-user-logged-in-event
- dev-add-hasmany-relationship
- dev-remove-stubs
- dev-add-model-id
- dev-bug-fixes
- dev-add-log-date
This package is auto-updated.
Last update: 2026-02-20 21:28:44 UTC
README
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require threls/activity-log
You can publish and run the migrations with:
php artisan vendor:publish --tag="activity-log-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="activity-log-config"
This is the contents of the published config file:
return [ 'enabled' => env('ACTIVITY_LOG_ENABLED', true), 'log_events' => [ 'on_create' => true, 'on_update' => true, 'on_delete' => true, 'on_login' => true, ], // When true, updates will only log changed (dirty) attributes 'log_only_dirty' => true, // The User model class used to resolve causer name/id 'user_model' => '\App\Models\User', // Which attribute on the causer to display in descriptions (e.g. name/email) 'causer_name_attribute' => 'name', // Global fallback identifier used in descriptions when a model doesn't override it 'default_log_identifier' => 'id', // API listing pagination size 'log_pagination' => 20, // Middleware used by the built-in logs API route 'api_route_middleware' => 'auth:sanctum', // Number of days to retain logs before pruning (default 365) 'retention_days' => 365, ];
Usage
- Add the
LogsActivitytrait to any model you want to track. - Implement
ActivityLogContractto strongly define your model's logging configuration. - By default, descriptions are standardized as:
"{causerName} {verb} {ModelName} '{identifier}'".
Basic
use Threls\ThrelsActivityLog\Traits\LogsActivity; class Product extends Model { use LogsActivity; }
This will emit logs like: Sabina created Product '42' using the global default_log_identifier.
Per-model configuration via properties (no interface)
class Product extends Model { use LogsActivity; public ?array $logAttributes = ['name', 'price']; public ?array $ignoreAttributes = ['updated_at']; public ?bool $logOnlyDirty = true; // only diffs on update public ?string $logIdentifier = 'name'; // used in description }
Strict configuration via interface
use Threls\ThrelsActivityLog\Contracts\ActivityLogContract; use Threls\ThrelsActivityLog\Enums\ActivityLogTypeEnum; class Product extends Model implements ActivityLogContract { use LogsActivity; public function getLogAttributes(): array|string|null { return ['name', 'price']; } public function getIgnoreAttributes(): array|string|null { return ['updated_at']; } public function getLogOnlyDirty(): ?bool { return true; } public function getLogIdentifier(): ?string { return 'name'; } }
CLI / Queues safety
- The package guards request-dependent values (user agent, IP). In non-HTTP contexts, defaults like
unknownand127.0.0.1are used.
Maintenance
Log Pruning (Recommended)
This package supports Laravel's native model pruning. To keep your activity_log table small, you should schedule the model:prune command in your application's routes/console.php (or app/Console/Kernel.php for older Laravel versions):
use Illuminate\Support\Facades\Schedule; use Threls\ThrelsActivityLog\Models\ActivityLog; Schedule::command('model:prune', [ '--model' => [ActivityLog::class], ])->daily();
You can configure the retention period in config/activity-log.php:
'retention_days' => 365, // Keep logs for 1 year
Manual Cleanup
Alternatively, you can manually delete old logs using the provided command:
# Deletes logs older than 30 days php artisan activity-log:delete --older-than-days=30 # Deletes logs using the 'retention_days' from config php artisan activity-log:delete
Built-in API to list logs
GET /threls-activity-log/logs
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.