The Laravel Audit Log package is designed to provide detailed audit logging for Laravel applications:
Laravel Audit Logger is a powerful and flexible package designed to provide detailed audit logging for Laravel applications. It enables tracking of all changes to your Eloquent models with comprehensive source tracking, ensuring compliance with regulatory requirements, aiding in debugging, and maintaining data integrity.
The package uses a high-performance direct logging architecture while maintaining flexibility through optional event integration, making it suitable for both small applications and enterprise-scale systems.
You can make any model auditable by adding the package's provided trait:
namespace App\Models; use Illuminate\Database\Eloquent\Model;use iamfarhad\LaravelAuditLog\Traits\Auditable; class Order extends Model{ use Auditable; protected $fillable = ['customer_id', 'total', 'status'];}
Using the Auditable
trait, all your model changes are logged to a dedicated audit table. In the above example, the audit table would be named audit_order_logs
. You can also query audit logs for a model using the provided EloquentAuditLog
class:
use iamfarhad\LaravelAuditLog\Models\EloquentAuditLog; $httpLogs = EloquentAuditLog::forEntity(Order::class) ->fromHttp() ->get(); // Get all logs for a given order$orderLogs = $order->auditLogs()->get();
Main Features
- Entity-Specific Audit Tables: Automatically creates dedicated tables for each audited model to optimize performance and querying.
- Comprehensive Change Tracking: Logs all CRUD operations (create, update, delete, restore) with old and new values.
- Source Tracking: Automatically tracks the source of changes (console commands, HTTP routes, etc.) for enhanced debugging and compliance.
- Customizable Field Logging: Control which fields to include or exclude from auditing.
- User Tracking: Automatically identifies and logs the user (causer) responsible for changes.
- And more...
You can learn more about this package, get full installation instructions, and view the source code on GitHub. You can install this package with the following Composer command:
composer require iamfarhad/laravel-audit-logphp artisan vendor:publish --tag=audit-logger-config