Download the PHP package souravmsh/audit-trail without Composer
On this page you can find all versions of the php package souravmsh/audit-trail. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download souravmsh/audit-trail
More information about souravmsh/audit-trail
Files in souravmsh/audit-trail
Package audit-trail
Short Description AuditTrail a Laravel package for managing audit logs
License MIT
Homepage https://github.com/souravmsh/audit-trail
Informations about the package audit-trail
AuditTrail a Laravel package for managing audit logs
Audit Trail is a Laravel package that provides an easy-to-use mechanism for maintaining table row audit logs. It automatically tracks changes to database records, including created, updated, and deleted events, making it easier to monitor data modifications and user activities.
Installation
1. You can install the package via Composer:
2. Alternatively, you can install it manually:
Create directories:
Clone git repository:
Add below lines to laravel/composer.json file:
Then,
3. Publish and Run Migrations
To publish and run the migrations, use:
This will create the necessary database tables for logging audit records.
Usage
1. Logging Audit Data
You can manually log audit records using the AuditTrail facade:
Log an audit trail entry using the AuditTrail package.
This example demonstrates how to log changes made to a specific model. The audit log captures details such as the type of action performed, the model being updated, the changed data, and the user responsible.
Parameters:
- type: The action type (CREATED, UPDATED, DELETED, LOGGEDIN, IMPORTED, EXPORTED, OTHER).
- message: (Optional) message.
- model_type: The fully qualified class name of the model being logged.
- model_id: The specific model instance ID associated with the change.
- data: An array containing changes, specifying old and new values.
2. Access model directly
3. Retrieving Audit History
To fetch the audit log for a specific model:
4. Blade Component for Displaying Audit Logs:-
You can use the built-in Blade component widget to display audit logs in your UI:
Blade Component for Displaying Audit Logs
This component is used to display audit trail logs in the UI. You can configure various parameters to filter and control the displayed logs.
Parameters:
- title: The title of the audit trail widget.
- per_page: Number of records displayed per page.
- limit: Maximum number of audit logs to fetch.
- model_type: The target model type for which logs are fetched.
- model_id: The specific model instance ID to filter logs.
- creator_type: The type of creator who performed the action (e.g., User, Admin).
- creator_id: The specific creator ID to filter logs.
- show_model: Set to "true" to load data with the 'model' relation, which links to the target table.
- show_creator: Set to "true" to load data with the 'creator' relation, which links to the user who performed the action.
also, you can pass request query parameters:
5. Adding Custom Styles
To ensure the audit trail widget looks great, include the custom CSS file in your Blade template. Add the following <link>
tag to the <head>
section of your template:
Testing
Run tests using:
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.