PHP code example of grazulex / laravel-snapshot

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

    

grazulex / laravel-snapshot example snippets


use Grazulex\LaravelSnapshot\Traits\HasSnapshots;

class Order extends Model
{
    use HasSnapshots;
}

// Create snapshots
$order = Order::find(1);
$order->snapshot('before-discount');

$order->update(['total' => 99.99]);
$order->snapshot('after-discount');

// Compare and restore
$diff = $order->compareWithSnapshot('before-discount');
$order->restoreFromSnapshot('before-discount');

// CLI usage
php artisan snapshot:save "App\Models\Order" --id=1 --label=backup
php artisan snapshot:restore "App\Models\Order" 1 backup
php artisan snapshot:diff before-discount after-discount