PHPackages                             hristijans/laravel-database-masker - 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. [Database &amp; ORM](/categories/database)
4. /
5. hristijans/laravel-database-masker

ActiveLibrary[Database &amp; ORM](/categories/database)

hristijans/laravel-database-masker
==================================

Laravel package for creating masked database dumps with sensitive data obfuscated

v2.0.4(1y ago)43MITPHPPHP ^8.0

Since Apr 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/hristijans/laravel-database-masker)[ Packagist](https://packagist.org/packages/hristijans/laravel-database-masker)[ RSS](/packages/hristijans-laravel-database-masker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (14)Versions (6)Used By (0)

Laravel Database Masker
=======================

[](#laravel-database-masker)

A Laravel package for creating masked database dumps with sensitive data obfuscated, following modern PHP 8.3 best practices. Perfect for providing realistic data to developers without exposing confidential information.

Features
--------

[](#features)

- **Selective Column Masking**: Configure which columns in which tables contain sensitive data
- **Type-Aware Masking**: Automatically generates appropriate fake data based on column types
- **Multiple Database Support**: Process multiple database connections at once
- **Modern Architecture**: Uses design patterns (Strategy, Factory, Template) for maintainable, extensible code
- **PHP 8.3 Ready**: Leverages the latest PHP features with strict typing
- **Database Agnostic**: Supports MySQL, PostgreSQL, and SQLite
- **Relationship Preservation**: Maintains database relationships and integrity
- **Performance Optimized**: Processes large databases efficiently with batching
- **Developer-Friendly**: Easy to use Artisan commands for creating and restoring masked dumps

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 10.0+

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require hristijans/laravel-database-masker
```

After installing the package, publish the configuration file:

```
php artisan vendor:publish --provider="Hristijans\DatabaseMasker\DatabaseMaskerServiceProvider" --tag="config"
```

Configuration
-------------

[](#configuration)

Edit the published configuration file at `config/database-masker.php` to define which tables and columns contain sensitive data that should be masked.

### Single Database Configuration

[](#single-database-configuration)

For simple projects with a single database:

```
return [
    'tables' => [
        'users' => [
            'columns' => [
                'email' => ['type' => 'email'],
                'name' => ['type' => 'name'],
                'phone' => ['type' => 'phone'],
                // Add more columns as needed
            ],
        ],
        // Add more tables as needed
    ],

    'exclude_tables' => [
        'migrations',
        'failed_jobs',
        // Add more tables to exclude
    ],

    // Global configuration
    'preserve_primary_keys' => true,
    'preserve_foreign_keys' => true,
    'batch_size' => 1000,
];
```

### Multiple Database Configuration

[](#multiple-database-configuration)

For projects with multiple database connections:

```
return [
    'connections' => [
        'mysql' => [
            'tables' => [
                'users' => [
                    'columns' => [
                        'email' => ['type' => 'email'],
                        'name' => ['type' => 'name'],
                    ],
                ],
            ],
            'exclude_tables' => ['migrations', 'failed_jobs'],
            'output_file' => 'masked_mysql.sql',
        ],
        'customer_db' => [
            'tables' => [
                'customers' => [
                    'columns' => [
                        'email' => ['type' => 'email'],
                        'first_name' => ['type' => 'firstName'],
                        'last_name' => ['type' => 'lastName'],
                    ],
                ],
            ],
            'exclude_tables' => ['migrations'],
            'output_file' => 'masked_customer_db.sql',
        ],
    ],

    // Global configuration
    'preserve_primary_keys' => true,
    'preserve_foreign_keys' => true,
    'batch_size' => 1000,
    'output_path' => storage_path('app'),
];
```

Available Mask Types
--------------------

[](#available-mask-types)

The package supports various mask types for different kinds of data:

Mask TypeDescriptionAdditional Options`email`Replaces with a fake email address-`name`Replaces with a fake full name-`firstName`Replaces with a fake first name-`lastName`Replaces with a fake last name-`phone`Replaces with a fake phone number`format`: e.g., '###-###-####'`address`Replaces with a fake address-`city`Replaces with a fake city name-`country`Replaces with a fake country name-`postcode`Replaces with a fake postal/zip code-`text`Replaces with random text`length`: Maximum length`randomNumber`Replaces with a random number`min`, `max`: Range limits`date`Replaces with a random date`format`: Date format (default: Y-m-d)`datetime`Replaces with a random datetime`format`: Date format (default: Y-m-d H:i:s)`numerify`Replaces with a pattern of numbers`format`: e.g., '###-##-####'`lexify`Replaces with random letters`format`: e.g., '????'`bothify`Mix of numbers and letters`format`: e.g., '##??'`regexify`Based on regex pattern`regex`: Regular expression pattern`creditCardNumber`Fake credit card number-`company`Fake company name-`url`Fake URL-`ipv4`Fake IPv4 address-`ipv6`Fake IPv6 address-`uuid`Random UUID-`password`Bcrypt hash of random password-Usage
-----

[](#usage)

### Single Database

[](#single-database)

#### Creating a Masked Database Dump

[](#creating-a-masked-database-dump)

To create a masked database dump:

```
php artisan db:mask-dump
```

By default, the dump will be saved to `storage/app/masked_database.sql`. You can specify a custom output file:

```
php artisan db:mask-dump --output=/path/to/output.sql
```

#### Creating and Restoring a Masked Database in One Step

[](#creating-and-restoring-a-masked-database-in-one-step)

To create a masked database dump and immediately restore it to your local database:

```
php artisan db:mask-restore
```

This will create a masked dump and then restore it to your database, effectively replacing your current database with the masked version.

You can also restore an existing masked dump:

```
php artisan db:mask-restore --no-dump --input=/path/to/masked_dump.sql
```

To skip the confirmation prompt, use the `--force` option:

```
php artisan db:mask-restore --force
```

### Multiple Databases

[](#multiple-databases)

#### Creating Masked Database Dumps for All Configured Connections

[](#creating-masked-database-dumps-for-all-configured-connections)

To create masked dumps for all configured database connections:

```
php artisan db:mask-dump
```

This will generate a separate SQL file for each connection, with the filenames specified in your configuration.

#### Creating a Masked Database Dump for a Specific Connection

[](#creating-a-masked-database-dump-for-a-specific-connection)

To create a masked dump for a specific database connection:

```
php artisan db:mask-dump --connection=customer_db
```

#### Specifying an Output Directory

[](#specifying-an-output-directory)

You can specify a custom output directory for all dump files:

```
php artisan db:mask-dump --output-path=/path/to/directory
```

#### Restoring a Masked Database to a Specific Connection

[](#restoring-a-masked-database-to-a-specific-connection)

To restore a masked dump to a specific connection:

```
php artisan db:mask-restore --connection=customer_db
```

### Using a Custom Configuration File

[](#using-a-custom-configuration-file)

You can specify a custom configuration file for one-off operations:

```
php artisan db:mask-dump --config=/path/to/custom-config.php
```

Extending the Package
---------------------

[](#extending-the-package)

### Adding Custom Mask Types

[](#adding-custom-mask-types)

You can extend the package with your own masking strategies:

```
use Hristijans\DatabaseMasker\Contracts\ValueMaskerInterface;
use Faker\Factory as FakerFactory;

class MyCustomMasker implements ValueMaskerInterface
{
    private $faker;

    public function __construct()
    {
        $this->faker = FakerFactory::create();
    }

    public function canHandle(string $type): bool
    {
        return $type === 'my_custom_type';
    }

    public function mask(mixed $originalValue, array $columnConfig): mixed
    {
        // Your custom masking logic here
        return "masked_{$originalValue}";
    }
}
```

Then register it with the MaskerStrategyFactory:

```
// In a service provider
use Hristijans\DatabaseMasker\Services\Factories\MaskerStrategyFactory;

public function boot(): void
{
    $this->app->make(MaskerStrategyFactory::class)
        ->registerMasker(new MyCustomMasker());
}
```

### Supporting Additional Database Types

[](#supporting-additional-database-types)

To add support for additional database types, implement the `DatabaseDriverInterface` and update the `DatabaseDriverFactory`.

Example Workflow for New Developers
-----------------------------------

[](#example-workflow-for-new-developers)

When a new developer joins the team:

1. The senior developer runs `php artisan db:mask-dump` on production (or a copy)
2. The masked SQL dump(s) are provided to the new developer
3. The new developer imports the masked dump(s) into their local environment
4. The new developer can now work with realistic data without seeing confidential information

Using with Large Databases
--------------------------

[](#using-with-large-databases)

For large databases, you may want to adjust the `batch_size` in the configuration to process records in smaller batches:

```
'batch_size' => 500, // Process 500 records at a time
```

This helps to reduce memory usage when processing large tables.

Testing
-------

[](#testing)

```
composer test
```

Security
--------

[](#security)

If you discover any security issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance49

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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 ~2 days

Total

4

Last Release

373d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a53974885fd8a42bad42be77ff822086bf14c45602340933d3e1082eab5c282?d=identicon)[hristijans](/maintainers/hristijans)

---

Top Contributors

[![hristijans](https://avatars.githubusercontent.com/u/8149688?v=4)](https://github.com/hristijans "hristijans (12 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/hristijans-laravel-database-masker/health.svg)

```
[![Health](https://phpackages.com/badges/hristijans-laravel-database-masker/health.svg)](https://phpackages.com/packages/hristijans-laravel-database-masker)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[ryangjchandler/orbit

A flat-file database driver for Eloquent.

922256.2k5](/packages/ryangjchandler-orbit)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[baril/bonsai

An implementation of the Closure Tables pattern for Eloquent.

3593.5k](/packages/baril-bonsai)

PHPackages © 2026

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