Download the PHP package iamfarhad/laravel-audit-log without Composer

On this page you can find all versions of the php package iamfarhad/laravel-audit-log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-audit-log

Laravel Audit Logger

Latest Version on Packagist Total Downloads PHP Version Laravel Version GitHub stars

License Maintained Tests Code Style PHPStan Scrutinizer Code Quality

Overview

Laravel Audit Logger is a powerful and flexible package designed to provide comprehensive audit logging for Laravel applications. It enables tracking of all changes to your Eloquent models with advanced features including source tracking, queue processing, and customizable field management, ensuring compliance with regulatory requirements, aiding in debugging, and maintaining data integrity. Built with modern PHP and Laravel practices, this package adheres to strict typing, PSR-12 coding standards, and leverages dependency injection for maximum testability and maintainability.

The package uses a high-performance direct logging architecture with optional queue integration, making it suitable for both small applications and enterprise-scale systems.

Table of Contents

Features

Requirements

Installation

Install the package via Composer:

After installation, publish the configuration file to customize settings:

This will create a configuration file at config/audit-logger.php where you can adjust settings like the storage driver, table naming conventions, queue processing, and more.

Configuration

The configuration file config/audit-logger.php allows you to customize the behavior of the audit logger. Below are the key configuration options:

Environment Variables

You can use environment variables to configure the audit logger:

Database Schema

The audit logger creates tables with the following structure for each audited model:

The source field is automatically populated to track the origin of changes:

Usage

Basic Usage

To make a model auditable, simply add the Auditable trait to your Eloquent model. Ensure strict typing is enabled as per the engineering rules.

Once the trait is added, any changes to the model (create, update, delete, restore) will be automatically logged to a dedicated audit table (e.g., audit_orders_logs).

Authenticated User Tracking

The audit logger automatically tracks WHO made the change and WHERE it came from:

Retrieving Audit Logs with User Information

You can easily retrieve audit logs with user information:

Advanced User Tracking Examples

Example 1: Track User Changes in Controller

Example 2: Track System Changes in Console Commands

Example 3: Custom Metadata with User Context

Example 4: Querying Audit Logs by User and Source

Configuration for User Tracking

The causer (user) resolution can be configured in the config/audit-logger.php file:

Custom Causer Resolver

You can create a custom causer resolver for complex scenarios:

Register your custom resolver in a service provider:

Excluding Fields

To exclude specific fields from being audited, define the $auditExclude property:

Including Specific Fields

Alternatively, you can specify only the fields to audit using $auditInclude:

Advanced Usage

Custom Metadata

You can enrich audit logs with custom metadata by implementing the getAuditMetadata method in your model:

Source Tracking

The audit logger automatically tracks the source of changes to help with debugging and compliance. The source field captures:

Enhanced Query Scopes for Source Filtering

Query audit logs by source using convenient scopes:

Temporarily Disabling Auditing

For specific operations where auditing is not required, you can disable it temporarily:

Custom Audit Events with Fluent API

To log custom actions beyond standard CRUD operations, use the fluent API provided by the audit() method:

This fluent interface provides:

Queue Processing

The audit logger supports both synchronous and asynchronous processing of audit logs for improved performance in high-traffic applications.

Enabling Queue Processing

Update your configuration to enable queue processing:

Or use environment variables:

Queue Jobs Architecture

The package includes two specialized queue jobs:

  1. ProcessAuditLogJob: Handles standard asynchronous audit log processing
  2. ProcessAuditLogSyncJob: Provides fallback synchronous processing when needed

Queue Configuration Options

Benefits of Queue Processing

  1. Improved Performance: Audit logging doesn't block your application's main thread
  2. Scalability: Handle high-volume audit logging without impacting user experience
  3. Reliability: Failed audit logs can be retried automatically with Laravel's queue system
  4. Resource Management: Control when and how audit logs are processed
  5. Better Error Handling: Queue-specific error handling and monitoring

Queue Worker Setup

When using queue processing, ensure you have queue workers running:

For production environments, consider using Supervisor or similar process managers to keep your queue workers running reliably.

Customizing Audit Logging

Custom Driver Implementation

If you need to extend the audit logging functionality, you can implement a custom driver by adhering to the AuditDriverInterface:

Register your custom driver in a service provider:

Custom Causer Resolver

You can implement a custom causer resolver for complex authentication scenarios:

Retrieving Audit Logs

Model Relationship

Audit logs are accessible via a relationship on the audited model:

Advanced Querying with EloquentAuditLog

For more complex queries, use the EloquentAuditLog model directly with comprehensive scopes:

Available Query Scopes

The EloquentAuditLog model provides comprehensive scopes for efficient filtering:

Entity and Basic Filtering

Date Filtering

Enhanced Source Filtering

Performance Optimization

Database Optimization

Application-Level Optimization

Recommended Configuration for High-Traffic Applications

Monitoring and Maintenance

Testing

This package includes a comprehensive test suite with high coverage. To run the tests locally:

Test Categories

The test suite includes:

Testing Your Implementation

When writing tests for your application, ensure you cover audit logging behavior:

Security Best Practices

Data Protection

Access Control

Data Retention and Compliance

Audit Log Retention

The Laravel Audit Logger package includes a powerful retention system that helps you manage the lifecycle of your audit logs. This system supports automatic cleanup, anonymization, and archiving of old audit data to help with compliance requirements and database performance.

Features

Configuration

Global Configuration

Configure retention settings in your config/audit-logger.php:

Environment Variables

Per-Entity Configuration

Configure retention settings for specific entities:

Per-Model Configuration

Configure retention directly in your model:

Retention Strategies

1. Delete Strategy

Permanently removes old audit logs from the database.

Use Case: When you want to minimize storage usage and don't need historical data beyond a certain period.

2. Anonymize Strategy

Replaces sensitive information with anonymized values while keeping the audit structure intact.

Anonymized Fields: email, phone, address, ip_address, user_agent, name, first_name, last_name, full_name

Use Case: Compliance requirements where you need to maintain audit trail structure but remove personally identifiable information.

3. Archive Strategy

Moves old audit logs to a separate database connection for long-term storage.

Use Case: Long-term compliance requirements where you need to maintain historical data but keep the primary database lean.

4. Combined Strategy

You can combine anonymization with deletion or archiving:

Usage

Manual Execution

Queue Processing

Scheduled Execution

Add to your app/Console/Kernel.php:

Service Usage

Best Practices

  1. Start with Dry Runs: Always test your retention policies with --dry-run before applying
  2. Monitor Performance: Use appropriate batch sizes for your database performance
  3. Backup Strategy: Ensure you have backups before running retention operations
  4. Compliance Review: Review your retention policies with legal/compliance teams
  5. Gradual Implementation: Start with longer retention periods and adjust based on requirements
  6. Queue Processing: Use queued processing for large datasets to avoid timeouts

Security Considerations

Migration & Upgrade Guide

Upgrading from Version 1.2.x to 1.3.x

Version 1.3.0 introduced breaking changes with the move from event-driven to direct logging architecture:

Breaking Changes

Migration Steps

  1. Update Configuration: Publish the new configuration file:

  2. Database Schema: Add the source column to existing audit tables:

  3. Remove Event Listeners: If you were listening to ModelAudited events, replace with direct service usage or custom implementations.

  4. Test Your Implementation: Ensure all audit logging continues to work as expected.

Upgrading from Version 1.1.x to 1.2.x

Version 1.2.0 introduced structural changes:

Most changes are backward compatible, but you should update any direct references to the old AuditLog model class.

Troubleshooting

Common Issues and Solutions

Audit Tables Not Created

Missing Logs

Causer Not Recorded

Source Field Issues

Queue Processing Issues

Performance Issues

Static Analysis Errors

Debug Mode

Enable debug logging to troubleshoot issues:

Getting Help

  1. Check Documentation: Review this README and the changelog
  2. Search Issues: Look through existing GitHub issues
  3. Create Issue: If you find a bug, create a detailed issue with:
    • Laravel version
    • PHP version
    • Package version
    • Minimal reproduction steps
    • Expected vs actual behavior

Contributing

Contributions are welcome! Please follow these guidelines:

Development Setup

  1. Fork the Repository: Create your own fork of the project
  2. Clone Locally: git clone your-fork-url
  3. Install Dependencies: composer install
  4. Run Tests: composer test to ensure everything works

Code Standards

Pull Request Process

  1. Create Branch: Create a feature branch from main
  2. Write Code: Implement your changes following the code standards
  3. Add Tests: Include comprehensive tests for your changes
  4. Update Documentation: Update README and changelog as needed
  5. Run Quality Checks:

  6. Submit PR: Create a detailed pull request with description of changes

Code Quality Tools

The project uses several quality assurance tools:

License

This package is open-sourced software licensed under the MIT license.


Laravel Audit Logger - Comprehensive audit logging for modern Laravel applications with advanced source tracking, queue processing, and enterprise-grade features.


All versions of laravel-audit-log with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/events Version ^10.0|^11.0|^12.0
illuminate/config Version ^10.0|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package iamfarhad/laravel-audit-log contains the following files

Loading the files please wait ....