Download the PHP package asif/laravel-model-logs without Composer
On this page you can find all versions of the php package asif/laravel-model-logs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-model-logs
Laravel Model Logs
The laravel-model-logs package provides an easy way to track changes made to your Eloquent models and log them into an audit_logs
table. It allows you to keep a history of all the modifications made to your models, making it useful for auditing purposes, user activity tracking, and more.
Installation
You can install the package via Composer by running the following command:
After installing the package, Laravel will automatically discover the service provider.
Usage
Step 1: Set up the Database
Before using the package, you need to create the audit_logs table in your database. You can use the provided migration file to create the table by running the migration:
Step 2: Add the LogChanges Trait to Your Models
To start tracking changes on your models, add the LogChanges trait to each model you want to monitor. The trait provides the necessary functionality to automatically log changes whenever the model is created, updated, or deleted.
Step 3: Customize Tracked Events (Optional)
By default, the LogChanges trait tracks all events: 'created', 'updated', and 'deleted'. However, you can customize the tracked events for each model by adding a $trackedEvents property to the model. If the property is not defined, the package will track all events.
Step 4: Define Loggable Fields (Optional)
You can further customize the fields that should be logged for each model by adding a $loggable property to the model, containing an array of field names that you want to track. If the property is not provided, the package will log all the fields.
License
The laravel-model-logs package is open-sourced software licensed under the MIT License.