PHP code example of watheqalshowaiter / backup-tables

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

    

watheqalshowaiter / backup-tables example snippets


use WatheqAlshowaiter\BackupTables\BackupTables; // import the facade

class ChangeSomeData
{
    public function handle()
    {
        BackupTables::generateBackup('users');
        // result: users_backup_2024_08_22_17_40_01
       
        // change some data..
    }
}

BackupTables::generateBackup(['users', 'posts']); 
// users_backup_2024_08_22_17_40_01
// posts_backup_2024_08_22_17_40_01 

BackupTables::generateBackup(User::class);
// users_backup_2024_08_22_17_40_01

// or

BackupTables::generateBackup([User::class, Post::class]);
// users_backup_2024_08_22_17_40_01, posts_backup_2024_08_22_17_40_01 

BackupTables::generateBackup('users', 'Y_d_m_H_i');
// users_backup_2024_22_08_17_40

BackupTables::generateBackup('users', 'Y_d_m_H');
// can not generate the same backup in the same hour

BackupTables::generateBackup('users', 'Y_d_m');
// can not generate the same backup in the same day
bash
php artisan backup:tables users posts
# users_backup_2024_08_22_17_40_01, posts_backup_2024_08_22_17_40_01

php artisan backup:tables \\App\\Models\\User \\App\\Models\\Post
# users_backup_2024_08_22_17_40_01, posts_backup_2024_08_22_17_40_01