cbytedigital/nen7513-audit-logging

NEN 7513-compliant Laravel package for audit logging

dev-main 2025-08-20 15:56 UTC

This package is not auto-updated.

Last update: 2025-08-21 14:13:24 UTC


README

PHP from Packagist Latest Version on Packagist Software License Total Downloads

A comprehensive NEN 7513-compliant Laravel package for audit logging, designed specifically for healthcare applications and other environments requiring detailed activity tracking and compliance with Dutch healthcare standards.

This package automatically tracks and logs all user interactions with your Laravel application's data, capturing who, what, when, where, why, and how for complete audit traceability.

Key Features

  • NEN 7513 Compliant - Meets Dutch healthcare logging standards
  • Automatic Logging - Zero-configuration CRUD operation tracking
  • Flexible API - Multiple ways to log: automatic, facade, or trait methods
  • Rich CREATE Logging - Configurable full model data logging on creation
  • Parent-Child Logging - Child model changes automatically log on parent with full context
  • Data Privacy - Automatic masking of sensitive fields
  • Smart Actor Detection - Automatically identifies users, guests, or system processes
  • Retention Management - Configurable cleanup with NEN 7513 compliance
  • Advanced Querying - Powerful filtering and search capabilities
  • Web Dashboard - Beautiful, responsive audit log viewer with export functionality

Installation

Use composer to install this package:

composer require cbytedigital/nen7513-audit-logging

Publish and run the migration:

php artisan vendor:publish --tag=audit-log
php artisan migrate

Quick Start

Add the Auditable trait to any model you want to track:

<?php

use CbyteDigital\Nen7513AuditLogging\Traits\Auditable;
use Illuminate\Database\Eloquent\Model;

class Patient extends Model
{
    use Auditable;
    
    public function getAuditName(): string
    {
        return $this->first_name . ' ' . $this->last_name;
    }
}

That's it! All CRUD operations are now automatically logged:

$patient = Patient::create(['name' => 'John Doe']);     // Logged
$patient->update(['name' => 'John Smith']);             // Logged
$patient->delete();                                     // Logged

Usage Examples

Automatic Logging

// All operations automatically logged with the Auditable trait
$patient = Patient::find(1);
$patient->update(['status' => 'discharged']);

Manual Logging with Facade

use CbyteDigital\Nen7513AuditLogging\Facades\AuditLog;

AuditLog::read($patient, 'Patient medical record accessed');
AuditLog::failed('Unauthorized access attempt')
    ->forActor($user)
    ->read($patient);

Parent-Child Logging

// Child model changes automatically logged on parent
class ClientHistory extends Model 
{
    use ParentAuditable;
    
    protected static function getParentAuditConfig(): array
    {
        return [
            'parent_relation' => 'client',
            'actions' => ['create', 'update', 'delete'],
        ];
    }
}

Documentation

Support

Version Laravel Version PHP Version
1.x ^11.0|^12.0 ^8.2

Testing

Run the tests with:

composer test
# or
php vendor/bin/phpunit

Postcardware

This package is completely free to use. If it makes it to your production environment we would highly appreciate you sending us a postcard from your hometown! 👏🏼

Our address is: CBYTE Digital B.V., Parallelweg 27, 5223AL 's-Hertogenbosch, Netherlands.

License

The MIT License (MIT). Please see License File for more information.