Download the PHP package dineshstack/laravel-audit without Composer

On this page you can find all versions of the php package dineshstack/laravel-audit. 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

dineshstack/laravel-audit

Activity log & audit trail for Laravel 13. Auto-log every Eloquent model change — with field-level diffs, IP capture, user attribution, batch grouping, data masking, and a full REST API — in one composer require.

Latest Version on Packagist Total Downloads PHP Version Laravel


Why this package?

Most Laravel audit packages store a flat JSON blob and call it done. laravel-audit goes further:


Requirements

Dependency Version
PHP ^8.3
Laravel ^13.0
league/csv ^9.15
dompdf/dompdf ^2.0
guzzlehttp/guzzle ^7.8

Installation

audit:install publishes config/audit.php, publishes and optionally runs the migration, and appends the required environment variable stubs to your .env file.

If you prefer to publish assets manually:


Quick start

1. Auto-log any Eloquent model

Add the LogsActivity trait to the models you want to audit:

That's it. Every create, update, and delete on Invoice is now logged with the changed attributes, old and new values, the authenticated user, their IP address, user agent, and the full request URL.

2. Manual logging

Use the fluent builder for events that aren't model-driven:

All methods except log() and save() are optional:

Method Description
->on(Model $subject) The model being acted upon
->with(array $data) Arbitrary context stored in properties
->by(?Model $causer) Who did it — defaults to auth()->user()
->description(string $desc) Human-readable label stored alongside the event key

3. Batch logging

Wrap multiple operations in AuditLog::batch() to link them under a shared batch_id. This lets you query or replay an entire multi-step transaction as a unit:

All entries created inside the closure share the same UUID batch_id.


Field-level diffs

When a model is updated, the package computes a precise diff of only the changed fields:

Unchanged fields are never stored. Added fields report "type": "added" with old: null; removed fields report "type": "removed" with new: null.

Controlling which fields are logged

Override these two methods in your model:


Data masking

Any field whose name contains a masked keyword is stored as [REDACTED] in both the old/new snapshots and the diff. The default masked keywords are:

Customize via .env (comma-separated, case-insensitive substring matching):

Or publish and edit config/audit.php directly.


REST API

All endpoints are prefixed with /api/audit and optionally protected by a token set in AUDIT_TOKEN. Pass the token as either:

If AUDIT_TOKEN is empty, all endpoints are unauthenticated (suitable for internal networks).

Endpoints

GET /api/audit/feed

Paginated activity feed with filtering.

Query parameters:

Parameter Type Description
event string Filter by event name (e.g. update, payment.processed)
causer_id integer Filter by user ID
subject_type string Filter by model class (e.g. App\Models\Invoice)
ip_address string Filter by IP address
date_from date Filter entries on or after this date
date_to date Filter entries on or before this date
search string Full-text search across description and properties
batch_id string Show all entries in a specific batch
per_page integer Results per page (default: 30, max: 100)
page integer Page number

Response:

GET /api/audit/entry/{id}

Single audit entry by ULID — includes full properties payload.

GET /api/audit/timeline

Chronological activity for a specific user, ordered by most recent.

Parameter Description
causer_id Required. The user's ID
causer_type Defaults to App\Models\User
per_page Default: 30

GET /api/audit/stats

Aggregated statistics for a date range.

Response shape:

GET /api/audit/causers

Distinct causers with activity counts — for populating filter dropdowns. Returns the most recently seen name per causer_id, so renamed users appear only once.

GET /api/audit/export/csv

Exports the filtered log as a .csv file. Accepts the same filter parameters as /feed. Maximum 10,000 rows per export; exports are tracked for alert rate-limiting.

GET /api/audit/export/pdf

Exports a formatted PDF audit trail report. Accepts the same filters as /feed. Powered by dompdf/dompdf.

Alert rule endpoints

Method Endpoint Description
GET /api/audit/alerts List all rules and default thresholds
POST /api/audit/alerts Create an alert rule
PUT /api/audit/alerts/{id} Update or enable/disable a rule
DELETE /api/audit/alerts/{id} Delete a rule
GET /api/audit/alerts/history Recent fired-alert history

Create rule request body:


Alert rules

Alert rules fire when a threshold is exceeded. The package checks patterns synchronously after every AuditEntry is saved.

Default thresholds (configurable via .env)

Rule Default Environment variable
Deletes per minute 10 AUDIT_ALERT_DELETES_PER_MIN
Logins per minute 20 AUDIT_ALERT_LOGINS_PER_MIN
Updates per minute 50 AUDIT_ALERT_UPDATES_PER_MIN
Exports per hour 5 AUDIT_ALERT_EXPORTS_PER_HOUR

Custom rules created via the API override these defaults for matching event patterns.

Notification channels

Mailgun (email):

Slack:


Retention pruning

Logs are automatically pruned daily by a scheduled command registered in the service provider. The retention window defaults to 90 days:

Run pruning manually at any time:

Ensure your Laravel scheduler is running:


Database schema

Three tables are created by the package migration:

audit_logs

Column Type Description
id ULID (PK) Universally unique, lexicographically sortable
event string Event key, e.g. update, payment.processed
description string Human-readable label
batch_id string Groups entries from one AuditLog::batch() call
subject_type string Audited model class
subject_id string Audited model primary key
causer_type string Actor model class (usually App\Models\User)
causer_id integer Actor primary key
causer_name string Snapshot of the actor's name at time of action
properties JSON old, new, diff, and any custom with() data
ip_address string Request IP (supports IPv6)
user_agent text Full user-agent string
url text Full request URL
method string HTTP method
created_at timestamp Indexed for fast date-range queries

Indexes on: event, batch_id, ip_address, created_at, and composite morphs indexes on (subject_type, subject_id) and (causer_type, causer_id).

audit_alert_rules

Stores custom threshold rules created via the API.

audit_alert_history

Records every fired alert with the rule name, metric value, threshold breached, and the channels notified.


Configuration reference

After publishing with php artisan vendor:publish --tag=audit-config, your config/audit.php exposes:


Testing

The package ships with a PHPUnit test suite covering DiffService and MaskingService:

Test coverage includes:

To run tests against a specific Laravel application using Testbench:


Pro Dashboard

The free package exposes the REST API. To get a full visual interface — activity feed, user timeline, statistics charts, field diff viewer, CSV/PDF export, and alert rule management — pick up the Pro Dashboard:

👉 dineshstack.com/laravel-audit

Built with Next.js 16, React 19, Recharts, and TanStack Query. Self-hosted, dark/light mode, Docker-ready.


Changelog

See CHANGELOG.md for recent changes.

Contributing

Pull requests are welcome. Please open an issue first to discuss significant changes. All contributions must include tests.

Security

If you discover a security vulnerability, please email [email protected] instead of opening a public issue. All disclosures are reviewed within 48 hours.

License

MIT. See LICENSE for the full text.

Author

Dinesh Wijethungadineshwijethunga.me


All versions of laravel-audit with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^10.0|^11.0|^12.0|^13.0
illuminate/console Version ^10.0|^11.0|^12.0|^13.0
illuminate/queue Version ^10.0|^11.0|^12.0|^13.0
guzzlehttp/guzzle Version ^7.8
league/csv Version ^9.15
dompdf/dompdf Version ^2.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 dineshstack/laravel-audit contains the following files

Loading the files please wait ...