PHPackages                             webhubworks/laravel-secure-db-dump - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. webhubworks/laravel-secure-db-dump

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

webhubworks/laravel-secure-db-dump
==================================

Allows you to dump your db and anonymize its content.

1.0.11(1mo ago)092MITPHPPHP ^8.2|^8.3CI passing

Since May 28Pushed 1mo agoCompare

[ Source](https://github.com/webhubworks/laravel-secure-db-dump)[ Packagist](https://packagist.org/packages/webhubworks/laravel-secure-db-dump)[ Docs](https://github.com/webhubworks/secure-db-dump)[ RSS](/packages/webhubworks-laravel-secure-db-dump/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (22)Versions (13)Used By (0)

Usage
=====

[](#usage)

Call `artisan secure-db-dump:run` to export data based on the following config.

Note

The original database is **never modified**. It is only read (dumped); all anonymization happens on the separate `temp_secure_db_dump` database.

The command performs these steps:

1. **Setup** – resolves the source DB connection (`db_connection` config, falls back to default), the storage `disk`, and builds the dump file paths (`{database}_{Ymd_His}.sql.gz`).
2. **Dump original database** – exports the source DB via `spatie/db-dumper` (gzip-compressed) to `original_dump_*.sql.gz` on the configured disk.
3. **Setup temp database** – runs `CREATE DATABASE IF NOT EXISTS temp_secure_db_dump`, registers it as a runtime connection, and switches the default connection to it.
4. **Import dump** – pipes the original dump through `gunzip | mysql` into `temp_secure_db_dump`, then truncates any tables listed in `ignore_tables`.
5. **Anonymize** – iterates the configured `anonymize_fields` table-by-table, applying each `AnonymizerConfig` (`faker` or `static`, optional `where` filters) via `UPDATE` statements on the temp DB. After every row's field rules, any configured `row_hooks` callables for that table are invoked (see [Row hooks](#row-hooks)).
6. **Dump secure database** – exports `temp_secure_db_dump` (gzip-compressed) to `secure_dump_*.sql.gz`. Schema is omitted when `only_content` is enabled.
7. **Clean up** – drops `temp_secure_db_dump` (skipped on local env; falls back to dropping individual tables if `DROP DATABASE` fails).
8. **Prompt** – asks whether to delete the original dump file, then prints the path to the secure dump.

Use `--only-anonymize` to skip steps 2, 4, 6, 7 and 8 and just (re-)anonymize an already-imported `temp_secure_db_dump`.

**Outcome:**

- Source database: read-only (dumped, never modified).
- `temp_secure_db_dump`: created, populated, mutated, then dropped (kept around on local env for inspection).
- Files written to the configured disk (default `local`): `original_dump_{database}_{timestamp}.sql.gz` (optionally deleted at the end) and `secure_dump_{database}_{timestamp}.sql.gz` (the final anonymized dump).

DDEV
====

[](#ddev)

In case you get a permission error when trying to CREATE or DROP a database, add this post-start hook to your `.ddev/config.yaml`:

```
...
hooks:
  post-start:
    - exec: mysql -uroot -proot -e "GRANT ALL ON *.* TO 'db'@'%'; FLUSH PRIVILEGES;"
      service: db
```

Config
======

[](#config)

Publish the config file via `artisan vendor:publish --tag=secure-db-dump-config`.

Anonymize fields
----------------

[](#anonymize-fields)

This package uses Faker to anonymize fields. You can find the available formatters/methods here:

Per field you want to anonymize you have to define the `field` and a `type`. Possible values are: `faker` or `static`.

### Type: static

[](#type-static)

You will need to provide a `value` for the field.

### Type: faker

[](#type-faker)

You will need to provide a `method` and optionally `args` (an array) for the Faker method.

### Examples

[](#examples)

```
...
'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}']),
        ],
    ],
...
```

Row hooks
---------

[](#row-hooks)

`anonymize_fields` covers per-field replacements only. When you need logic that goes beyond replacing a single column — for example inserting related records, reusing one generated value across several tables, or any cross-row coordination — register a **row hook** under the `row_hooks` config key.

Each hook is a `callable(\Faker\Generator $faker, object $row): void` registered against a table. The runner iterates the table's rows once and, **for each row**, first applies every matching `anonymize_fields` rule and then invokes every registered hook in order. The `$row` passed to a hook is the value read from the cursor (pre-anonymization); to read freshly anonymized values, re-query the row from the temp database, e.g. `DB::table('projects')->where('id', $row->id)->first()`.

A table may appear in `row_hooks` without any `anonymize_fields` entry — the hook will still fire for every row in that table.

Like `anonymize_fields`, `row_hooks` accepts either an inline array or a fully qualified class name. The class must be invokable and return the same array shape.

### Example

[](#example)

For each `projects` row, generate a unique 4-digit number, create a fresh `cost_centers` record titled `"{number} - {project title}"`, and attach it to the project:

```
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]);
        },
    ],
],
```

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance90

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~89 days

Total

12

Last Release

46d ago

PHP version history (2 changes)1.0.0PHP ^8.3

1.0.1PHP ^8.2|^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/53560154?v=4)[webhub](/maintainers/webhubworks)[@webhubworks](https://github.com/webhubworks)

---

Top Contributors

[![marventhieme](https://avatars.githubusercontent.com/u/53627227?v=4)](https://github.com/marventhieme "marventhieme (28 commits)")

---

Tags

laravelwebhubworkssecure-db-dump

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/webhubworks-laravel-secure-db-dump/health.svg)

```
[![Health](https://phpackages.com/badges/webhubworks-laravel-secure-db-dump/health.svg)](https://phpackages.com/packages/webhubworks-laravel-secure-db-dump)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
