Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Auditable

Laravel Auditable Laravel Package

ss-ipg/laravel-auditable

Attribute-driven audit logging for Laravel Eloquent models. Add #[Auditable] to track created/updated/deleted/soft-deleted/restored events with old/new diffs, include/exclude/redact filters, JSON formatting for log aggregation, and extensible context metadata.

View on GitHub
Deep Wiki
Context7

Declarative model audit logging for Laravel using PHP attributes

Frequently asked questions about Laravel Auditable
How do I audit changes to Eloquent models without writing custom event listeners?
Simply add the `#[Auditable]` attribute to your model. The package automatically tracks created, updated, deleted, soft-deleted, and restored events with old/new value diffs. No manual event binding or logging code is required.
Does this package support Laravel 10 or earlier versions?
No, Laravel Auditable requires Laravel 11+ and PHP 8.3+ due to its reliance on PHP attributes. If you're on an older version, consider alternatives like `owen-it/laravel-auditing` or `spatie/laravel-activitylog`.
Can I exclude or redact sensitive fields like passwords from audit logs?
Yes. Use the `exclude` or `redact` options in the `#[Auditable]` attribute to filter out sensitive fields. For example, `#[Auditable(exclude: ['password', 'api_token'])]` will omit those fields from logs.
How do I add custom metadata (e.g., request ID, tenant ID) to audit logs?
Implement a `AuditContextProvider` class and register it in the `context_providers` array in `config/auditable.php`. The provider’s `getContext()` method can return any metadata you need, like `['request_id' => $request->id, 'tenant_id' => Auth::tenant()->id]`.
Will mass updates (e.g., `Model::where(...)->update()`) trigger audit logs?
No, mass operations bypass auditing because they don’t operate on individual model instances. To audit bulk changes, iterate over models explicitly, like `Model::where(...)->get()->each(fn($model) => $model->update(...))`.
How do I test audit logs in PHPUnit or Pest?
Use the `Audit::fake()` helper to assert audit logs in tests. For example: `Audit::fake(); $user->update(['name' => 'New Name']); Audit::assertLogged(fn($log) => $log->hasChanges(['name' => 'New Name']));`.
Can I send audit logs to Datadog, Splunk, or other monitoring tools?
Yes. The package outputs logs in JSON format by default, which is compatible with most monitoring tools. Configure your logging channel (e.g., `monolog` with a `DatadogHandler`) to forward audit logs to your preferred destination.
How do I disable auditing for specific models or environments?
Disable auditing for all models by setting `AUDITABLE_ENABLED=false` in `.env`. To exclude specific models, omit the `#[Auditable]` attribute. Restrict environments via `environments` in `config/auditable.php` (e.g., `['production', 'staging']`).
Does this package handle soft deletes and restores automatically?
Yes. The package detects soft deletes (`deleted_at` updates) and restores (`deleted_at` nullification) separately from hard deletes. Each event type is logged with the appropriate context, making it easy to track compliance-sensitive changes.
What are the performance implications of enabling auditing in production?
Audit logging adds I/O overhead, which can impact performance for high-volume models. Mitigate this by enabling async logging (e.g., using the `queue` channel) or sampling logs for non-critical models. Disable auditing in non-production environments via `environments` config.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/entity-migrator
codraw/doctrine-extra
codraw/aws-tool-kit
codraw/validator
codraw/workflow
codraw/open-api
codraw/cron-job
codraw/process
codraw/log
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony