Quick Start
Install the bundle, add only the optional Symfony packages you need, migrate the
audit table, and mark your first Doctrine entity with #[Auditable].
Install The Package
composer require rcsofttech/audit-trail-bundle
The synchronous database transport works without additional runtime packages. Install optional packages only for the features you enable.
Requirements: AuditTrailBundle 4.x requires PHP 8.4, Symfony 7.4 or 8.0,
Doctrine ORM 3.6, and ext-mbstring.
| Feature | Package |
|---|---|
| Async database transport | composer require symfony/messenger |
| Queue transport | composer require symfony/messenger |
| HTTP transport | composer require symfony/http-client |
| EasyAdmin dashboard | composer require easycorp/easyadmin-bundle |
Database Setup
If you use the default database transport, generate and run a migration for the audit log table.
php bin/console make:migration
php bin/console doctrine:migrations:migrate
Async database mode uses a delivery identifier for worker retries. If you enable or upgrade to async database delivery, generate and run the migration before workers process messages.
Quick Start
Add #[Auditable] to any Doctrine entity you want to track. You can ignore noisy
properties at the entity level.
<?php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Rcsofttech\AuditTrailBundle\Attribute\Auditable;
#[ORM\Entity]
#[Auditable(ignoredProperties: ['internalCode'])]
class Product
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
public private(set) ?int $id = null;
public function __construct(
#[ORM\Column(length: 180)]
public private(set) string $name,
#[ORM\Column]
public private(set) int $priceInCents,
#[ORM\Column(length: 40, nullable: true)]
public private(set) ?string $internalCode = null,
) {
}
}
When the entity is created, updated, deleted, or changed through tracked collections, the bundle builds an audit log with action, changed fields, old values, new values, user context, request metadata, and transaction data.
Minimal Configuration
The database transport is enabled by default. Add a config file when you want explicit defaults or when you enable additional features.
# config/packages/audit_trail.yaml
audit_trail:
enabled: true
ignored_properties: ['updatedAt', 'updated_at']
retention_days: 365
transports:
database:
enabled: true
async: false