Skip to content
Icon

WARNING You're browsing the documentation for an upcoming version of Laravel Auditable. The documentation and features of this release are subject to change.

Installation

Laravel Auditable can be installed via Composer. More details about this package can be found on Packagist.

Requirements

  • PHP 8.3+
  • Laravel 13.0+

Installation

Run the following command in your project to get the latest version of the package:

composer require yajra/laravel-auditable:"^13"

Configuration

Publish the configuration file:

php artisan vendor:publish --tag=auditable

This will publish the auditable.php configuration file to your config directory.

Default Configuration

The package provides default values for creator, updater, and deleter when no user is authenticated:

// config/auditable.php
return [
'defaults' => [
'creator' => [
'name' => '',
],
'updater' => [
'name' => '',
],
'deleter' => [
'name' => '',
],
],
];

Custom User Class

To use a custom user class for a specific model, define the auditUser property on your model:

namespace App\Models;
 
use Yajra\Auditable\AuditableTrait;
use Illuminate\Database\Eloquent\Model;
 
class Post extends Model
{
use AuditableTrait;
 
protected $auditUser = App\Models\Admin::class;
}

Custom Column Names

To use custom column names instead of the defaults (created_by and updated_by), define constants on your model:

namespace App\Models;
 
use Yajra\Auditable\AuditableTrait;
use Illuminate\Database\Eloquent\Model;
 
class Post extends Model
{
use AuditableTrait;
 
public const CREATED_BY = 'author_id';
public const UPDATED_BY = 'last_editor_id';
}