PHP code example of lukasjankowski / laravel-revision

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

    

lukasjankowski / laravel-revision example snippets


'providers' => [
    // ...
    LukasJankowski\Revision\RevisionServiceProvider::class
];

use Illuminate\Database\Eloquent\Model;
use LukasJankowski\Revision\Traits\HasRevision;
 
class Post extends Model
{
    use HasRevisions;
    
    // ...
}

use Illuminate\Foundation\Auth\User as Authenticatable;
use LukasJankowski\Revision\Traits\IsReviser;
 
class User extends Authenticatable
{
    use IsReviser;
    
    // ...
}

use Illuminate\Database\Eloquent\Model;
use LukasJankowski\Revision\Traits\HasRevision;
 
class Post extends Model
{
    use HasRevisions;
    
    /**
     * The fields, which will not be logged in the revisions.
     *
     * @var array
     */
    protected $revisionExclude = [
        'password', 'remember_token',
    ];
    
    /**
     * The threshold, which will limit the revisions to that number.
     *
     * @var int
     */
    protected $revisionThreshold = 123;
    
    // ...
}

    $post = App\Post::find(1);
    $post->revisions; // Returns all revisions made to this record in a collection.

    $post = App\Post::find(1);
    $post->revisions()->with('revisers')->get(); // Same as above, but eager load the ones, who performed the revision.

    $user = App\User::find(1);
    $user->revised; // Returns all revisions made by this record in a collection.

    $user = App\User::find(1);
    $user->revised()->with('revisions')->get(); 
    // Same as above, but eager load the models on which the revisions were performed.

    $post = App\Post::find(1);
    $post->revisions->first();
    $post->revisions->last();
    $post->revisions->find(12);
    // ...

    $post = App\Post::find(1);
    $revision = $post->revisions->first();
    $revision->getModified();
    // Which will return an associative array similar to this:
    [
        'title' => [
            'new' => 'Fresh and new',
            'old' => 'Old and stale',
        ],
        'body' => [
            'new' => 'Lorem ipsum...',
            'old' => 'Placeholder.Place...',
        ],
    ];
 config/app.php 

php artisan vendor:publish --provider="LukasJankowski\Revision\RevisionServiceProvider" --tag="config"

php artisan vendor:publish --provider="LukasJankowski\Revision\RevisionServiceProvider" --tag="migrations"
 config/revision.php 

php artisan migrate
 config/revision.php