PHP code example of develoopin / revisionable

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

    

develoopin / revisionable example snippets


"develoopin/revisionable": "1.*",

namespace MyApp\Models;

class Article extends Eloquent {
    use \Develoopin\Revisionable\RevisionableTrait;

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

use Develoopin\Revisionable\Revisionable;

namespace MyApp\Models;

class Article extends Revisionable { }

namespace MyApp\Models;

class Article extends Eloquent {
    use Develoopin\Revisionable\RevisionableTrait;

    protected $revisionEnabled = false;
}

namespace MyApp\Models;

class Article extends Eloquent {
    use Develoopin\Revisionable\RevisionableTrait;

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

namespace MyApp\Models;

class Article extends Eloquent {
    use Develoopin\Revisionable\RevisionableTrait;

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

protected $revisionCreationsEnabled = true;

protected $keepRevisionOf = array(
    'title'
);

protected $dontKeepRevisionOf = array(
    'category_id'
);

// app/Providers/EventServiceProviders.php
public function boot(DispatcherContract $events)
{
    parent::boot($events);

    $events->listen('revisionable.*', function($model, $revisions) {
        // Do something with the revisions or the changed model. 
        dd($model, $revisions);
    });
}


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

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

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

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

@foreach($resource->revisionHistory 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 Develoopin\Revisionable\Revisionable;

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

protected $revisionNullString = 'nothing';
protected $revisionUnknownString = 'unknown';

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

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

php composer.phar update

php artisan migrate --path=vendor/develoopin/revisionable/src/migrations

php artisan migrate --package=develoopin/revisionable