PHP code example of pderas / archivalist

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

    

pderas / archivalist example snippets


use Pderas\Archivalist\Traits\HasArchives;
class Post extends Model {
    use HasArchives;
}

use Pderas\Archivalist\Traits\HasArchives;
class Post extends Model {
    use HasArchives;

    protected $archived = [
        'updated_at'
    ];

    // Alternatively...
    protected function archived() {
        return [
            'updated_at' => $this->getOriginal('updated_at'),
            'is_archived' => true
        ];
    }
}

$user->company = 'Pderas';
$user->save();

$archive = $user->archives()->first(); // => \Pderas\Archivalist\Models\Archive
$original = $archive->rehydrate(); // => \App\User

$user->getHistory(); // A user model for every state the user was in

//  Do not do
Post::where('status','open')
    ->update(['status','closed']); // This will fail

//  Do this instead
Archivalist::proxy(Post::query())
    ->where('status','open')
    ->update(['status','closed']);

// SomeModel which uses HasArchives

public function beforeArchive() {
    //  Put logic here to be ran before the primary archives logic is ran
    //  useful for automating tasks such as always writing user->id, etc
}