asseco-voice/laravel-blueprint-audit

Laravel support for additional blueprint methods

Downloads

4436

Stars

0

Version

v2.0.0

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();
    });
}
asseco-voice

Author

asseco-voice