Download the PHP package foxen/laravel-model-activity-log without Composer
On this page you can find all versions of the php package foxen/laravel-model-activity-log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download foxen/laravel-model-activity-log
More information about foxen/laravel-model-activity-log
Files in foxen/laravel-model-activity-log
Package laravel-model-activity-log
Short Description A simple Laravel package to log model activity.
License MIT
Informations about the package laravel-model-activity-log
Laravel Model Activity Log
A simple Laravel package to automatically record basic activity (creation, updates with attribute changes, deletion, restoration) performed on specified Eloquent models, and provide a mechanism for automatically pruning old log entries.
Requirements
Installation
You can install the package via composer:
The package will automatically register its service provider.
To publish the configuration file, run the following command:
This will create a foxen_activitylog.php file in your config directory, which can be modified as required.
Finally, you need to run the migrations to create the activity_log table:
Usage
To enable activity logging for a model, simply use the LogsActivity trait in your model class:
The following events are automatically logged: created, updated, deleted. If your model uses SoftDeletes, the restored event is logged as well.
When an action is performed by an authenticated user, they are recorded as the causer. Actions performed without an authenticated user (e.g. from a console command or queue job) are attributed to System.
Customizing the Log Name
By default, the log name is set to default. You can customize this on a per-model basis by adding a protected $activityLogName property to your model:
Ignoring Attributes
To exclude certain attributes from the activity log when a model is created or updated, you can add a protected $ignoreActivityLogAttributes property to your model:
Redacting Attributes
To redact sensitive attributes from the activity log, you can add a protected $redactedActivityLogAttributes property to your model. The attribute key will be logged, but the value will be replaced with [REDACTED].
You can also configure global redacted attributes in the config/foxen_activitylog.php file.
Retrieving Logs
You can retrieve activity logs using the Foxen\LaravelModelActivityLog\Models\Activity model. The package provides several convenient query scopes:
You can access the subject and causer models directly via their relationships:
For updated events, the properties field contains the old and new values of changed attributes:
Pruning Logs
The package can automatically prune old activity log entries. To enable this, set the prune_activity_log option to true in your config/foxen_activitylog.php file and configure the prune_older_than_days option.
Once enabled, you must schedule the model:prune command in your application's routes/console.php file:
Testing
All versions of laravel-model-activity-log with dependencies
illuminate/support Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0