asseco-voice / laravel-blueprint-audit
Laravel support for additional blueprint methods
Installs: 6 419
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 3
Open Issues: 5
pkg:composer/asseco-voice/laravel-blueprint-audit
Requires
- php: ^8.1
- laravel/framework: ^10.0
Requires (Dev)
- fakerphp/faker: ^1.9.1
- mockery/mockery: ^1.4.4
- orchestra/testbench: ^8.5
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-10-10 02:08:03 UTC
README
Blueprint audit
Purpose of this repository is to provide additional methods for migrations.
Installation
Require the package with composer require asseco-voice/laravel-blueprint-audit.
Service provider will be registered automatically.
Usage
Call $table->audit() within your migration to get these attributes:
$this->timestamp('created_at')->nullable(); $this->string('created_by')->nullable(); $this->string('creator_type')->nullable(); $this->timestamp('updated_at')->nullable(); $this->string('updated_by')->nullable(); $this->string('updater_type')->nullable();
or call $table->softDeleteAudit() to additionally get also:
$this->timestamp('deleted_at')->nullable(); $this->string('deleted_by')->nullable(); $this->string('deleter_type')->nullable();
If you're using first one, add Audit trait on your model, and for
second one add SoftDeleteAudit trait to enable these attributes being
populated automatically.
_type field is there to support if you have more than one type of entities
which can perform actions on resources (i.e. service or user).
You can modify how the IDs and types are being extracted by publishing the config
with php artisan vendor:publish --tag=asseco-blueprint-audit and implementing
your own extractor class. Be sure your extended class implements Extractor
interface.
Runtime picker
There is a helper class which will enable you to pick timestamp types during runtime. So what you can do is define a config key which will be forwarded within a migration and will choose which migrations type to run.
Example, having the following migration:
public function up() { Schema::create('matches', function (Blueprint $table) { // ... // some fields // ... MigrationMethodPicker::pick($table, config('your-config.timestamps')); }); }
Config value being one of the MigrationMethodPicker types i.e. 'soft' will
evaluate your migration to:
public function up() { Schema::create('matches', function (Blueprint $table) { // ... // some fields // ... $table->timestamps(); $table->softDeletes(); }); }
