PHP code example of blalmal10a / db-archive

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

    

blalmal10a / db-archive example snippets


use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;
}

// Disable role checks entirely
' any set you want
'ddleware_group' => ['web'], // no auth middleware — accessible to all

// Or use your own custom middleware group
'middleware_group' => ['web', 'auth', 'custom-backup-guard'],

'controllers' => [
    'backup' => App\Http\Controllers\MyBackupController::class,
    'restore' => App\Http\Controllers\MyRestoreController::class,
],

namespace App\Http\Controllers;

use Blalmal10a\DbArchive\Http\Controllers\BackupController as BaseBackupController;

class MyBackupController extends BaseBackupController
{
    // override any method
}

return [
    'backup_path' => env('DBARCHIVE_BACKUP_PATH', 'backup'),
    'zip_path' => env('DBARCHIVE_ZIP_PATH', 'app/backup/zip'),
    'es',
        'backup_export' => '/backup/export',
        'backup_zip' => '/backup/zip',
        'backup_download' => '/backup/download/{fileName}',
        'backup_delete' => '/backup/{fileName}',
        'restore_index' => '/restore',
        'backup_restore' => '/backup/restore',
    ],
    'controllers' => [
        'backup' => Blalmal10a\DbArchive\Http\Controllers\BackupController::class,
        'restore' => Blalmal10a\DbArchive\Http\Controllers\RestoreController::class,
    ],
];

use Blalmal10a\DbArchive\DbArchive;

$dbArchive = app(DbArchive::class);

$dbArchive->exportTableToCsv('users', now()->format('Y-m-d_Hi'));
$dbArchive->zipBackup('2025-01-01_120000');

$backups = $dbArchive->listBackups();
$path = $dbArchive->downloadBackup('2025-01-01_120000');
$dbArchive->deleteBackup('2025-01-01_120000');
$dbArchive->restoreTable('users', $csvContent, $tableSQL, append: false);
bash
php artisan vendor:publish --tag="db-archive-config"
bash
php artisan vendor:publish --tag="db-archive-views"
bash
composer vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
php artisan migrate
bash
php artisan vendor:publish --tag="db-archive-config"