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

On this page you can find all versions of the php package vimatech/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 Log

Append-only, tenant-aware audit log for Laravel

CI Latest Version on Packagist Total Downloads License

It answers who did what, to which record, in which tenant, and what changed, and it guarantees that answer cannot be edited afterwards.

Why not an activity log?

Most activity-log packages are built for timelines, not for audit:

Laravel Audit Log is the small backend layer that fixes those three points and stops there.

Requirements

Feature Matrix

Feature Supported
Polymorphic tenant, actor, impersonator, subject ✅
Actor guard recorded (web, admin, …) ✅
Immutable rows at the model level ✅
Immutable rows at the database level (PostgreSQL, MySQL/MariaDB, SQLite triggers) ✅
Explicit Audit::record() and fluent builder ✅
Automatic diff for Eloquent models (Auditable) ✅
Hidden / excluded attributes kept out of the log ✅
Request context middleware (actor, request id, ip, user agent) ✅
Query scopes ✅
Retention policy contract, audit-log:prune ✅
UI, exports, dashboards ❌ deliberately
Cryptographic chaining of entries ❌ not yet

Installation

Publish the config if you need to rename the table, use a dedicated database connection, swap the model, list guards, require a tenant on every entry or choose a retention policy:

Register the middleware on the route groups where actions happen:

It has to run after the session has started. $middleware->append() puts it on the global stack instead, which runs before StartSession, and a session guard asked for a user at that point returns none: every entry is then recorded with no actor, and nothing reports it.

Recording

The middleware fills the actor, the actor guard, the request id, the ip and the user agent on the request-scoped AuditContext. The tenant, the impersonator and the reason are never resolved for you, because only your application knows where they come from: set them yourself, in your tenancy and impersonation layers, and set the whole context by hand in jobs and commands.

Each request starts from an empty context, and the context is cleared when the application terminates, so nothing carries over to the next request or the next queued job under Octane, FrankenPHP or a queue worker.

Tenant resolution

Three sources, in order: the tenant passed to the call, then the subject's own if it implements ProvidesAuditTenant, then the one on AuditContext.

The context is what covers the entries that have no subject, user.logged_in or export.generated, which would otherwise land with an empty tenant_id and never appear in a forTenant() query.

An action that genuinely belongs to no tenant says so, and that is different from not having thought about it:

withoutReason() does the same for the reason, against a context that carries one. In the fluent builder, inTenant() and because() take a value, never null: null used to mean "fall back", so there was no way to say "none".

Set audit-log.require_tenant to refuse any entry where none of the three sources produced a tenant. It is off by default: a null tenant is a faithful record of an action that had none, and not every application is multi-tenant. Turned on, it catches the call site that forgot, and the deliberate exceptions are the ones that called withoutTenant().

Automatic diffs

lease.created, lease.updated (changed attributes only, with before and after) and lease.deleted are recorded. Models using SoftDeletes also get lease.restored and lease.force_deleted, and a force delete never produces a duplicate lease.deleted. Timestamps, password, remember_token, hidden attributes and $auditExclude never reach the log. Keys are sorted so two identical changes produce identical diffs.

Values are recorded as stored in the database (raw attributes, before casting).

Reading

Reading is not isolated for you. There is no global scope and no policy on AuditEntry, so AuditEntry::query()->latestFirst()->paginate() in a tenant-facing controller returns every tenant's entries. Scope the query yourself, and authorize it like any other resource:

forCurrentTenant() throws when the context carries no tenant rather than returning everything. That is the whole reason there is no global scope here: one would filter on ambient state, so the same query would answer differently depending on who asked, and an audit log that quietly hides rows is worse than one that shows too many. The choice is left where it is visible.

Immutability

Every write path the package owns is closed. Updating or deleting an entry through a model throws AuditEntryIsImmutable, and so does every query builder method that writes without loading a row, which no model event would have seen: update(), delete(), forceDelete(), truncate(), upsert(), increment(), decrement(), incrementEach() and decrementEach(). A raw statement that goes around Eloquent entirely hits a database trigger and fails with audit log is append-only.

The triggers are not optional: the migration installs them and refuses to run on a driver that cannot carry them, rather than leaving a log that only looks append-only. The supported drivers are PostgreSQL, MySQL, MariaDB and SQLite.

What remains reachable, per engine:

Path PostgreSQL MySQL / MariaDB SQLite
UPDATE, DELETE blocked blocked blocked
TRUNCATE blocked, statement-level trigger not blockable, it is a drop and recreate no trigger observes n/a, compiled to DELETE and blocked
INSERT OR REPLACE n/a n/a passes unless PRAGMA recursive_triggers = ON
DROP TABLE, disabling the trigger privileges privileges privileges

The two holes in bold are properties of the engine, not choices. On MySQL, TRUNCATE needs the DROP privilege: withhold it from the application account. On SQLite, REPLACE skips delete triggers unless recursive triggers are enabled on the connection, which Laravel does not do for you.

Whatever the engine, an account that can drop the table or the trigger can defeat the log. Give the application an account that can insert and select, and nothing more, on a dedicated connection with audit-log.connection.

Transactions

A dedicated connection changes more than privileges: it changes what a rollback does to the entry. On the default connection, Audit::record() runs inside whatever transaction the business logic already opened, so a DB::transaction() that later throws rolls the audit entry back with it: the log then agrees with what is actually in the database. On a dedicated connection, the insert happens on a separate database session with its own transaction, so it survives a rollback of the business transaction: the log then asserts that an action was taken even though, from the application's point of view, it never happened.

Neither behavior is wrong, but they are not interchangeable. Choose the default connection when the log must agree with the data, and the dedicated connection when the log must survive whatever happens to the business transaction, including a crash mid-commit. Confirmed directly: wrapping Audit::record() in a DB::transaction() that later throws leaves the entries table empty on the default connection, and holding one entry on a dedicated connection.

Retention

The default policy keeps everything. KeepFor removes entries past an age:

A policy only answers where the boundary is:

The command owns the deletion, so no policy has to reach past the trigger. Schedule audit-log:prune, and look before you leap:

Deleting is the one operation the log allows, and it leaves its own trace: a successful prune records an audit_log.pruned entry carrying the policy, the range and the number of entries removed. A retention pass and an attempt to erase evidence are otherwise indistinguishable.

The delete path opens for the pruning database session alone, never for the server: PostgreSQL gates the trigger on a SET LOCAL setting, MySQL on a session variable. Neither survives the connection, so a killed process leaves nothing open and a concurrent connection is refused throughout. SQLite has no session state a trigger can read, so there the trigger is dropped and recreated inside a transaction: DDL is transactional on SQLite, so a crash rolls back to a protected table, and the write lock keeps every other connection out meanwhile.

Events

Vimatech\AuditLog\Events\AuditEntryRecorded is dispatched after every entry is written, whichever path wrote it: Audit::record(), the fluent builder, the Auditable trait, or audit-log:prune's own audit_log.pruned entry. It carries the AuditEntry instance:

Configuration

always_exclude is the only exclusion applied by default, five columns. Anything else, an email, a national ID, an attribute cast as encrypted, is written to before and after as recorded unless the model also lists it in $hidden or $auditExclude. An encrypted attribute is stored ciphertext rather than plaintext, but it is stored: decrypting it is one Crypt::decryptString() away for anyone who can read the table.

Testing

Contributing

Contributions are welcome.

Please ensure:

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our Security Policy for reporting vulnerabilities.

License

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

Credits

Built and maintained by Vimatech. Created by Adel Zemzemi, Laravel SaaS architect.


All versions of laravel-audit-log with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/console Version ^11.0|^12.0|^13.0
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.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 vimatech/laravel-audit-log contains the following files

Loading the files please wait ...