PHP code example of orisintel / laravel-model-auditlog

1. Go to this page and download the library: Download orisintel/laravel-model-auditlog library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

orisintel / laravel-model-auditlog example snippets


public function getAuditLogIgnoredFields() : array
{
    return ['posted_at'];
}

public function getAuditLogIgnoredFields() : array
{
    if ($this->postHasBeenPublished()) {
        return ['title'];
    }

    return [];
}

Schema::create('post_tag_auditlog', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->unsignedInteger('post_id')->index();
    $table->unsignedInteger('tag_id')->index();
    $table->unsignedTinyInteger('event_type')->index();
    $table->unsignedInteger('user_id')->nullable()->index();
    $table->string('field_name')->index();
    $table->text('field_value_old')->nullable();
    $table->text('field_value_new')->nullable();
    $table->timestamp('occurred_at')->index()->default('CURRENT_TIMESTAMP');
});

class PostTag extends Pivot
{
    use AuditLoggablePivot;

    /**
     * The array keys are the composite key in the audit log
     * table while the pivot table columns are the values.
     *
     * @var array
     */
    protected $audit_loggable_keys = [
        'post_id' => 'post_id',
        'tag_id'  => 'tag_id',
    ];
}

composer 

use Fico7489\Laravel\Pivot\Traits\PivotEventTrait;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use PivotEventTrait;

public function tags()
{
    return $this->belongsToMany(Tag::class)
        ->using(PostTag::class);
}

public function posts()
{
    return $this->belongsToMany(Post::class)
        ->using(PostTag::class);
}

composer 

use Awobaz\Compoships\Compoships;
use OrisIntel\AuditLog\Models\BaseModel;

class PostTagAuditLog extends BaseModel
{
    use Compoships;
 php
php artisan vendor:publish --provider="\OrisIntel\AuditLog\AuditLogServiceProvider"
sh
php artisan make:model-auditlog "\App\User"