PHP code example of kirilldakhniuk / dead-drop

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

    

kirilldakhniuk / dead-drop example snippets


use KirillDakhniuk\DeadDrop\Facades\DeadDrop;

// Simple export
DeadDrop::export('users');

// With date range
DeadDrop::export('users', [
    'where' => [
        ['created_at', '>=', '2024-01-01'],
        ['created_at', '<=', now()->toDateTimeString()]
    ]
]);

// Export all tables with date filter
DeadDrop::exportAll(null, null, [
    'where' => [
        ['created_at', '>=', now()->subMonth()->toDateTimeString()],
    ]
]);

// Nova/Filament integration
public function handle()
{
    $result = DeadDrop::export('users', [
        'where' => [
            ['created_at', '>=', $this->startDate],
        ]
    ]);

    return Action::download($result['file']);
}

return [
    'output_path' => storage_path('app/dead-drop'),

    'tables' => [
        'users' => [
            'columns' => ['id', 'name', 'email', 'created_at'],
            'censor' => ['email'],
            'defaults' => ['password' => 'password'], // Auto-hashed with bcrypt
            'where' => [['created_at', '>', now()->subDays(30)]],
            'limit' => 1000,
        ],
    ],
];

'tables' => [
    'table_name' => [
        'columns' => ['id', 'name', 'email'], // or '*' for all
        'censor' => ['email', 'phone'],
        'defaults' => ['password' => 'secret'],
        'where' => [
            ['status', '=', 'active'],
            ['created_at', '>', now()->subYear()],
        ],
        'order_by' => 'created_at DESC',
        'limit' => 1000,
    ],

    // Disable a table
    'logs' => false,
],

'users' => [
    'columns' => '*',
    'censor' => ['email', 'phone', 'address'],
],

'censor' => [
    'email' => 'companyEmail',
    'bio' => 'paragraph',
    'website' => 'domainName',
],

'users' => [
    'columns' => ['id', 'name', 'email'],
    'defaults' => ['password' => 'password'],
],

'spaces' => [
    'driver' => 's3',
    'key' => env('DO_SPACES_KEY'),
    'secret' => env('DO_SPACES_SECRET'),
    'region' => env('DO_SPACES_REGION', 'nyc3'),
    'bucket' => env('DO_SPACES_BUCKET'),
    'endpoint' => env('DO_SPACES_ENDPOINT'),
],

use KirillDakhniuk\DeadDrop\Exporter;
use KirillDakhniuk\DeadDrop\Importer;

// Export
$exporter = app(Exporter::class);
$result = $exporter->exportTable('users', 'mysql', storage_path('app/exports'));

// Import
$importer = app(Importer::class);
$result = $importer->importFromFile('/path/to/file.sql', 'mysql');
$result = $importer->importFromCloud('backups/users.sql', 's3', 'mysql');
bash
php artisan vendor:publish --tag=dead-drop-config
php artisan vendor:publish --tag=dead-drop-migrations
php artisan migrate