PHPackages                             ernestoch/user-auditable-for-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. ernestoch/user-auditable-for-laravel

ActiveLibrary[Database &amp; ORM](/categories/database)

ernestoch/user-auditable-for-laravel
====================================

Laravel package for user auditing in migrations and models

v1.3.1(1mo ago)433MITPHPPHP &gt;=8.1CI passing

Since Oct 16Pushed 1mo agoCompare

[ Source](https://github.com/3rn3st0/user-auditable-for-laravel)[ Packagist](https://packagist.org/packages/ernestoch/user-auditable-for-laravel)[ RSS](/packages/ernestoch-user-auditable-for-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (11)Used By (0)

User Auditable for Laravel
==========================

[](#user-auditable-for-laravel)

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/04744bae0a61d2ffe29c26f07a9612eae20445fc6feaeb77b3af1f0e9be6447c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d3838393242462e737667)](https://php.net/)[![Laravel Version](https://camo.githubusercontent.com/3029720d95207ba1c4973eb0c800378fdd7ef7d08c98da9430ceb7ab385bdd0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d253345253344392e302d4646324432302e737667)](https://laravel.com)[![Latest Version on Packagist](https://camo.githubusercontent.com/937cde3cb44fa4e2fa857601aee1905e6b6ace522f8052a517f73ac6f2e128b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65726e6573746f63682f757365722d617564697461626c652d666f722d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ernestoch/user-auditable-for-laravel)[![Tests](https://github.com/3rn3st0/user-auditable-for-laravel/actions/workflows/test.yml/badge.svg)](https://github.com/3rn3st0/user-auditable-for-laravel/actions/workflows/test.yml)[![Total Downloads](https://camo.githubusercontent.com/712b37ead1bf4714b893b8d0a2a9b838eb31b935c59039d4b848520fcf69d857/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f65726e6573746f63682f757365722d617564697461626c652d666f722d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ernestoch/user-auditable-for-laravel)

A Laravel package that provides user auditing capabilities for your database tables and Eloquent models. Easily track which users create, update, and delete records in your application.

Features
--------

[](#features)

- 🕵️ **User Auditing**: Automatically track `created_by`, `updated_by`, and `deleted_by`
- 🔧 **Flexible Macros**: Schema macros for easy migration creation
- 🎯 **Multiple Key Types**: Support for ID, UUID, and ULID
- 🏷️ **Relationships**: Built-in relationships to user models
- 📊 **Query Scopes**: Easy filtering by user actions
- ⚡ **Zero Configuration**: Works out of the box

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 9.0 or higher

> **Laravel 9 notice:** Laravel 9 reached End of Life in February 2024 and carries known security advisories. This package declares compatibility with Laravel 9 but CI tests for that version may fail due to Composer blocking EOL packages. Use Laravel 9 at your own risk.

Installation
------------

[](#installation)

```
composer require ernestoch/user-auditable-for-laravel
```

Configuration
-------------

[](#configuration)

Publish the configuration file (optional):

```
php artisan vendor:publish --tag=user-auditable-config
```

> **Note:** `fullAuditable()` requires `user_auditable` to also be listed in `enabled_macros`. If you disable `user_auditable` in the published config, registering `full_auditable` will throw a `RuntimeException` at boot time.

Usage
-----

[](#usage)

### Migrations

[](#migrations)

Use the provided macros in your migrations:

```
// Basic usage with default values
Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->fullAuditable(); // Adds timestamps, soft deletes, and user auditing
});

// Custom user table and UUID key type
Schema::create('products', function (Blueprint $table) {
    $table->uuid('id')->primary();
    $table->string('name');
    $table->fullAuditable('admins', 'uuid');
});

// Only user auditing columns (no timestamps or soft deletes)
Schema::create('settings', function (Blueprint $table) {
    $table->string('key')->primary();
    $table->text('value');
    $table->userAuditable('users', 'ulid');
});

// Reversing user auditing columns in a down() migration
Schema::table('posts', function (Blueprint $table) {
    $table->dropUserAuditable(); // Drops foreign keys and audit columns
});
```

#### Custom Event Columns

[](#custom-event-columns)

Use `eventAuditable()` to stamp any custom business event with its own `_at` timestamp and/or `_by` user FK, reading `user_table` and `key_type` from `config('user-auditable.defaults')`:

```
// Both columns: released_at (timestamp) + released_by (FK to users)
Schema::table('products', function (Blueprint $table) {
    $table->eventAuditable('released');
});

// Timestamp only: approved_at
Schema::table('orders', function (Blueprint $table) {
    $table->eventAuditable('approved', 'at');
});

// FK only: archived_by
Schema::table('posts', function (Blueprint $table) {
    $table->eventAuditable('archived', 'by');
});

// Reversing in a down() migration
Schema::table('products', function (Blueprint $table) {
    $table->dropEventAuditable('released'); // Drops FK + both columns
});
```

### Models

[](#models)

Use the `UserAuditable` trait in your Eloquent models:

```
