haseebmirza/laravel-compliance-export

Compliance-oriented export tools for Laravel applications.

Maintainers

Package info

github.com/haseebmirza/laravel-compliance-export

pkg:composer/haseebmirza/laravel-compliance-export

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-08-06 12:30 UTC

This package is auto-updated.

Last update: 2026-08-06 12:32:19 UTC


README

Compliance-oriented subject data exports for Laravel. Structured JSON/CSV/PDF output, configurable redaction, tamper-evident hashing, file saving, and a built-in preview workspace.

Installation

composer require haseebmirza/laravel-compliance-export

Publish the config:

php artisan vendor:publish --tag=compliance-export-config

Quick Start

use HaseebMirza\ComplianceExport\ComplianceExport;

$payload = ComplianceExport::for('user', 5)->toArray();
$json    = ComplianceExport::for('user', 5)->toJson();
$csv     = ComplianceExport::for('user', 5)->toCsv();
$pdf     = ComplianceExport::for('user', 5)->toFormat('pdf');

Subject Resolution

Map a subject type to a model:

// config/compliance-export.php
'subject_models' => [
    'user' => \App\Models\User::class,
],

Or register a custom resolver at runtime:

app(ComplianceExport::class)->registerSubjectResolver('user', function (string $subjectType, mixed $subjectId) {
    return User::query()->with('roles')->find($subjectId);
});

For richer integrations, implement a contextual source:

use HaseebMirza\ComplianceExport\Contracts\ContextualDataSource;
use HaseebMirza\ComplianceExport\Support\SubjectContext;

class NotesDataSource implements ContextualDataSource
{
    public function resolveForSubject(SubjectContext $subject): array
    {
        return [
            'subject_id' => $subject->subjectId(),
            'resolved' => $subject->isResolved(),
        ];
    }
}

Data Sources

Register custom data sources and request them in the export builder:

app(ComplianceExport::class)->registerSource('notes', function (string $subjectType, mixed $subjectId): array {
    return [
        ['body' => 'Performance review shared'],
        ['body' => 'Payroll profile updated'],
    ];
});

$payload = ComplianceExport::for('user', 5)
    ->withSource('notes')
    ->toArray();

Source Presets

Define reusable source groups in config:

// config/compliance-export.php
'presets' => [
    'default' => ['profile', 'activity'],
    'audit'   => ['profile', 'activity', 'notes'],
],

Then export with a preset:

$payload = ComplianceExport::for('user', 5)
    ->withPreset('audit')
    ->toArray();

Presets can be combined with explicit sources:

$payload = ComplianceExport::for('user', 5)
    ->withPreset('default')
    ->withSource('notes')
    ->toArray();

Output Formats

$json = ComplianceExport::for('user', 5)->toJson();
$csv  = ComplianceExport::for('user', 5)->toCsv();
$pdf  = ComplianceExport::for('user', 5)->toFormat('pdf');

Register custom exporters:

app(ComplianceExport::class)->registerExporter('txt', App\Exports\PlainTextExporter::class);

File Export

Save to a specific path:

$path = ComplianceExport::for('user', 5)
    ->saveTo(storage_path('app/exports/user-5.json'));

Or let the package generate a filename:

$path = ComplianceExport::for('user', 5)
    ->save(storage_path('app/exports'));

Save in any supported format:

ComplianceExport::for('user', 5)->saveFormat('csv', storage_path('app/exports'));
ComplianceExport::for('user', 5)->saveFormat('pdf', storage_path('app/exports'));

Meta and Validation

Append extra metadata to every export:

app(ComplianceExport::class)->mergeMeta([
    'exported_by' => 'compliance-bot',
    'request_reference' => 'REQ-1001',
]);

Register validators to enforce rules before an export is returned:

use HaseebMirza\ComplianceExport\Contracts\PayloadValidator;
use HaseebMirza\ComplianceExport\Exceptions\InvalidExportPayloadException;

class EmployeeOnlyValidator implements PayloadValidator
{
    public function validate(array $payload): void
    {
        if (($payload['meta']['subject_type'] ?? null) !== 'employee') {
            throw new InvalidExportPayloadException('Only employee exports are allowed.');
        }
    }
}

Preview UI

The package includes a built-in preview workspace at:

/compliance-export

Use it to preview exports, switch formats, validate presets and sources, and download files directly. Useful for testing the package after install and evaluating the export flow before deeper integration.

/compliance-export?subject_type=user&subject_id=5&format=csv

Configuration:

// config/compliance-export.php
'ui' => [
    'enabled' => true,
    'path' => 'compliance-export',
    'launcher' => [
        'enabled' => true,
        'local_only' => true,
    ],
],

Export Shape

{
  "meta": {
    "exported_at": "2026-08-06T12:00:00Z",
    "subject_type": "user",
    "subject_id": 5,
    "schema_version": "1.0",
    "hash": "sha256-hash"
  },
  "data": {
    "profile": {
      "id": 5,
      "type": "user"
    },
    "activity": []
  },
  "redactions": []
}

Good Fit

  • HR systems exporting employee records
  • CRM systems exporting customer histories
  • Internal audit workflows
  • Regulated admin systems needing controlled review exports
  • Support tools preparing record bundles

Testing

composer test

License

MIT