![]()
WARNING You're browsing the documentation for an upcoming version of Laravel Auditable. The documentation and features of this release are subject to change.
Auditable Schema Blueprint
The package provides Laravel Schema Blueprint macros for easily adding auditable fields to your migrations.
Adding Auditable Fields
Use the auditable() macro to add created_by and updated_by columns:
Schema::create('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->text('content'); $table->auditable(); $table->timestamps();});
This creates:
created_by-unsignedBigInteger, nullable, indexedupdated_by-unsignedBigInteger, nullable, indexed
Adding Auditable Fields with Soft Deletes
Use the auditableWithDeletes() macro to add created_by, updated_by, and deleted_by columns:
Schema::create('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->text('content'); $table->auditableWithDeletes(); $table->timestamps(); $table->softDeletes();});
This creates:
created_by-unsignedBigInteger, nullable, indexedupdated_by-unsignedBigInteger, nullable, indexeddeleted_by-unsignedBigInteger, nullable, indexed
Dropping Auditable Fields
Use the dropAuditable() macro to remove created_by and updated_by columns:
Schema::table('posts', function (Blueprint $table) { $table->dropAuditable();});
Dropping Auditable Fields with Deletes
Use the dropAuditableWithDeletes() macro to remove created_by, updated_by, and deleted_by columns:
Schema::table('posts', function (Blueprint $table) { $table->dropAuditableWithDeletes();});