PHP code example of webhubworks / laravel-secure-db-dump

1. Go to this page and download the library: Download webhubworks/laravel-secure-db-dump 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/ */

    

webhubworks / laravel-secure-db-dump example snippets


...
'anonymize_fields' => [

        # Specify the table name
        'users' => [
        
            # This will run $faker->name() for the 'name' field
            AnonymizerConfig::make()
                ->field('name')
                ->type('faker')
                ->method('name'),
            
            # This will run $faker->email() for the 'email' field
            AnonymizerConfig::make()
                ->field('email')
                ->type('faker')
                ->method('email'),
            
            # This will set the 'password' field to a static value
            AnonymizerConfig::make()
                ->field('password')
                ->type('static')
                ->value('$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'),
        
            # You can also add (multiple) where conditions.
            AnonymizerConfig::make()
                ->field('some_field')
                ->type('faker')
                ->method('sentence')
                ->where('some_field', fn($value) => $value === 'some_value'),
                ->where('some_other_field', fn($value) => ! str($value)->endsWith('@webhub.de')),
        ],
        
        'cars' => [
            # This will run $faker->regexify('LG [A-Z]{2} [0-9]{2,4}') for the 'licence_plate' field
            AnonymizerConfig::make()
                ->field('licence_plate')
                ->type('faker')
                ->method('regexify')
                ->args(['LG [A-Z]{2} [0-9]{2,4}']),
        ],
    ],
...

use Faker\Generator;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

'row_hooks' => [
    'projects' => [
        function (Generator $faker, object $row): void {
            $project = DB::table('projects')->where('id', $row->id)->first();

            do {
                $number = (string) random_int(1000, 9999);
            } while (DB::table('cost_centers')->where('number', $number)->exists());

            $costCenterId = (string) Str::uuid();

            DB::table('cost_centers')->insert([
                'id' => $costCenterId,
                'cost_center_group_id' => DB::table('cost_center_groups')->value('id'),
                'number' => $number,
                'title' => "{$number} - {$project->title}",
                'created_at' => now(),
                'updated_at' => now(),
            ]);

            DB::table('projects')
                ->where('id', $row->id)
                ->update(['cost_center_id' => $costCenterId]);
        },
    ],
],