PHP code example of samveloper / auditable

1. Go to this page and download the library: Download samveloper/auditable 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/ */

    

samveloper / auditable example snippets


"samveloper/auditable": "1.*",

namespace MyApp\Models;

class Article extends Eloquent {
    use \Samveloper\Auditable\AuditableTrait;

    public static function boot()
    {
        parent::boot();
    }
}

use Samveloper\Auditable\Auditable;

namespace MyApp\Models;

class Article extends Auditable { }

namespace MyApp\Models;

class Article extends Eloquent {
    use Samveloper\Auditable\AuditableTrait;

    protected $auditEnabled = false;
}

namespace MyApp\Models;

class Article extends Eloquent {
    use Samveloper\Auditable\AuditableTrait;

    protected $auditEnabled = true;
    protected $historyLimit = 500; //Stop tracking audits after 500 changes have been made.
}

namespace MyApp\Models;

class Article extends Eloquent {
    use Samveloper\Auditable\AuditableTrait;

    protected $auditEnabled = true;
    protected $auditCleanup = true; //Remove old audits (works only when used with $historyLimit)
    protected $historyLimit = 500; //Maintain a maximum of 500 changes at any point of time, while cleaning up old audits.
}

protected $auditCreationsEnabled = true;

protected $keepAuditOf = array(
    'title'
);

protected $dontKeepAuditOf = array(
    'category_id'
);

protected $auditFormattedFields = array(
    'title'  => 'string:<strong>%s</strong>',
    'public' => 'boolean:No|Yes',
    'modified' => 'datetime:m/d/Y g:i A',
    'deleted_at' => 'isEmpty:Active|Deleted'
);

protected $auditFormattedFieldNames = array(
    'title' => 'Title',
    'small_name' => 'Nickname',
    'deleted_at' => 'Deleted At'
);

$article = Article::find($id);
$history = $article->auditHistory;

@foreach($account->auditHistory as $history )
    <li>{{ $history->userResponsible()->first_name }} changed {{ $history->fieldName() }} from {{ $history->oldValue() }} to {{ $history->newValue() }}</li>
@endforeach

@foreach($resource->auditHistory as $history)
  @if($history->key == 'created_at' && !$history->old_value)
    <li>{{ $history->userResponsible()->first_name }} created this resource at {{ $history->newValue() }}</li>
  @else
    <li>{{ $history->userResponsible()->first_name }} changed {{ $history->fieldName() }} from {{ $history->oldValue() }} to {{ $history->newValue() }}</li>
  @endif
@endforeach

use Samveloper\Auditable\Auditable;

class Article extends Auditable
{
    public function identifiableName()
    {
        return $this->title;
    }
}

protected $auditNullString = 'nothing';
protected $auditUnknownString = 'unknown';

$object->disableAuditField('title'); // Disables title

$object->disableAuditField(array('title', 'content')); // Disables title and content

php artisan migrate --package=samveloper/auditable