PHP code example of sleavely / datadiff-laravel
1. Go to this page and download the library: Download sleavely/datadiff-laravel 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/ */
sleavely / datadiff-laravel example snippets
return array(
// ...
'providers' => array(
// ...
'Sleavely\Datadiff\Providers\DatadiffServiceProvider',
),
// ...
'aliases' => array(
// ...
'Datadiff' => 'Sleavely\Datadiff\Facades\DatadiffFacade',
),
);
return array(
'storage' => 'elasticsearch',
'elasticsearch' => array(
'hosts' => array(
'localhost:9200'
),
'index' => 'datadiffs',
),
);
// ...
MyEloquentPostModel::observe(new \Sleavely\Datadiff\DatadiffObserver);
MyEloquentCommentModel::observe(new \Sleavely\Datadiff\DatadiffObserver);
class MyEloquentPostModel extends Eloquent {
use \Sleavely\Datadiff\DatadiffTrait;
}
$post = Post::find(123);
$version = $post->diff_version; // 3, there are two older versions
$latestCommit = $post->diff(); // Returns latest version commit
$firstCommit = $post->diff(1); // Fetch version 1
$newPost = new Post;
$newPost->diff_version; // null
$newPost->diff(); // null
$post = Post::find(123);
$post->diff_meta = [
'my_custom_property' => 'hello world!',
'author_id' => Auth::user()->id,
];
$post->save();
class MyEloquentPostModel extends Eloquent {
use \Sleavely\Datadiff\DatadiffTrait;
public function getDiffMetaAttribute($value)
{
return [
'my_custom_property' => 'hello world!',
'author_id' => Auth::user()->id,
];
}
}
$obj1 = Post::find(111);
$obj2 = Post::find(222);
$diff = Datadiff::compare($obj1, $obj2);