PHP code example of local-dynamics / laravel-revisionable
1. Go to this page and download the library: Download local-dynamics/laravel-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/ */
local-dynamics / laravel-revisionable example snippets
"local-dynamics/laravel-revisionable": "1.*",
namespace App;
use \LocalDynamics\Revisionable\Concerns\IsRevisionable;
class Article extends \Illuminate\Database\Eloquent\Model {
use IsRevisionable;
}
namespace App;
use \LocalDynamics\Revisionable\Concerns\IsRevisionable;
class Article extends \Illuminate\Database\Eloquent\Model {
use IsRevisionable;
protected $revisionEnabled = false;
}
namespace App;
use \LocalDynamics\Revisionable\Concerns\IsRevisionable;
class Article extends \Illuminate\Database\Eloquent\Model {
use IsRevisionable;
protected $revisionEnabled = true;
protected $historyLimit = 500; //Stop tracking revisions after 500 changes have been made.
}
namespace App;
use \LocalDynamics\Revisionable\Concerns\IsRevisionable;
class Article extends \Illuminate\Database\Eloquent\Model {
use IsRevisionable;
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 = ['title'];
protected $dontKeepRevisionOf = ['category_id'];
// app/Providers/EventServiceProvider.php
public function boot()
{
parent::boot();
Event::listen('revisionable.*', function($model, $revisions) {
// Do something with the revisions or the changed model.
dd($model, $revisions);
});
}
@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 LocalDynamics\Revisionable\Concerns\IsRevisionable;
class Article
{
use IsRevisionable; // <- optional
public function identifiableName()
{
return $this->title;
}
}