Download the PHP package campelo/laravel-audit-log without Composer
On this page you can find all versions of the php package campelo/laravel-audit-log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-audit-log
Laravel Audit Log
Automatic audit logging for Laravel applications. Track who did what, when, where, and what changed.
Features
- Automatic Request Logging - Middleware logs all HTTP requests (POST, PUT, PATCH, DELETE by default)
- Model Event Logging - Trait to automatically log model changes (created, updated, deleted)
- Error Logging - Capture and log exceptions and errors (4xx, 5xx) with stack traces
- Performance Logging - Track slow database queries and slow HTTP requests
- Rollback - Revert model changes based on audit log history
- Detailed Information - Captures user, IP, user agent, URL, method, table, old/new values
- Built-in API - Query audit logs with filters via REST API
- Sensitive Data Protection - Automatically redacts passwords and sensitive fields
- Queue Support - Offload logging to queues for better performance
- Customizable - Configure which methods, routes, events, and error types to log
- Notifications - Send email/Slack alerts when critical errors occur
Installation
Publish the config and migrations:
Quick Start
1. Automatic Request Logging
The middleware is automatically registered. All POST, PUT, PATCH, DELETE requests will be logged.
2. Model Event Logging
Add the Auditable trait to your models:
3. Manual Logging
4. Error Logging
Automatically log all exceptions and errors that occur in your application.
Step 1: Configure in your .env:
Step 2: Integrate with your Exception Handler:
Manual error logging:
API Endpoints
The package provides built-in API endpoints to query audit logs:
List Audit Logs
Query Parameters:
| Parameter | Description | Example |
|---|---|---|
user_id |
Filter by user ID | ?user_id=1 |
event |
Filter by event type | ?event=updated or ?event=error |
events |
Multiple events (comma-separated) | ?events=created,updated |
table |
Filter by table name | ?table=users |
model |
Filter by model class | ?model=App\Models\User |
model_id |
Filter by model ID (requires model) | ?model=App\Models\User&model_id=1 |
method |
Filter by HTTP method | ?method=POST |
ip |
Filter by IP address | ?ip=192.168.1.1 |
route |
Filter by route name | ?route=users.update |
response_code |
Filter by HTTP response code | ?response_code=500 |
date_from |
Filter from date | ?date_from=2024-01-01 |
date_to |
Filter to date | ?date_to=2024-12-31 |
search |
Search in description, URL, user name/email | ?search=john |
per_page |
Items per page (max 100) | ?per_page=50 |
sort |
Sort field | ?sort=performed_at |
Examples:
| order | Sort order (asc/desc) | ?order=desc |
Get Single Entry
Get Logs for Model
Get Logs for User
Get Statistics
Returns:
- Total count
- Count by event type
- Count by table
- Count by HTTP method
- Top 10 users by activity
- Daily activity for last 30 days
Get Filter Options
Returns available values for events, tables, methods, and users.
Cleanup Old Logs
Automatic Cleanup
The package includes a command to clean up old audit logs based on retention policy.
Configuration
Automatic Cleanup (Recommended)
Enable automatic cleanup in your .env:
The package will automatically register the cleanup command in Laravel's scheduler. Make sure your server has cron configured:
Manual Cleanup
Run the cleanup command manually:
Manual Scheduler Registration
If you prefer to register the command manually in your app/Console/Kernel.php:
Notifications
Get notified via Email and/or Slack when critical errors (5xx) occur.
Configuration
Requirements
- Email: Uses Laravel's built-in mail configuration (
config/mail.php) - Slack: Requires the Slack notification channel package:
Throttling
To prevent notification spam, the package throttles repeated errors:
- Same error (same exception class + file + line) will only notify 5 times per hour
- Configurable in
config/audit-log.php:
Which errors trigger notifications
By default, only server errors (5xx) trigger notifications. You can customize via .env:
Or in config file:
Performance Logging
Track slow database queries and slow HTTP requests for performance monitoring.
Configuration
Querying Performance Logs
API Endpoints
Response Format
Slow Query:
Slow Request:
Rollback
Revert model changes based on audit log history. Only authorized users can perform rollback.
Configuration
Basic Rollback
Rollback from Model
Rollback Chain (Multiple Undos)
API Endpoints
Rollback Events
Each rollback creates a new audit log with event rollback:
Querying Rollbacks
Limitations
- created: Rollback deletes the model
- updated: Rollback restores old values
- deleted: Rollback restores soft-deleted models or recreates with old_values
- Cannot rollback events without
old_values(e.g., if not stored) - Cannot rollback non-model events (e.g.,
error,slow_query) - Each audit log can only be rolled back once
Query Using Model
Query Examples
Normal Operation Logs (CRUD)
Error Logs
Combined Queries
Accessing Audit Logs from Models
Configuration
Customization
Custom User Resolver
Custom Audit Data
Response Format
Normal Operation Log
Error Log
License
MIT
All versions of laravel-audit-log with dependencies
illuminate/support Version ^10.0|^11.0
illuminate/database Version ^10.0|^11.0
illuminate/http Version ^10.0|^11.0