Blur is a Laravel package that helps you obfuscate sensitive data in your database. It's perfect for creating anonymized copies of production databases for development and testing environments.
- 🔄 Obfuscate specific tables and columns in your database
- 🧩 Use Faker to generate realistic but fake data
- 🚀 Memory-optimized for handling large datasets
- 🔍 Interactive mode to select which tables to obfuscate
- 🛠️ Customizable obfuscation strategies
- 🔒 Safety checks to prevent running in production environments
You can install the package via composer:
composer require intermax/blurAfter installation, publish the configuration file:
php artisan vendor:publish --provider="Intermax\Blur\BlurServiceProvider"After publishing the configuration, you can find the configuration file at config/blur.php. Here's an example configuration:
<?php
declare(strict_types=1);
return [
'tables' => [
'users' => [
'columns' => [
'name' => 'faker:name',
'email' => 'faker:email',
// Add more columns as needed
],
// 'chunk_size' => 2000, // Optional: Set a chunk size; higher is faster but will use more memory
// 'keys' => ['id'], // Optional: Specify when the automatic discovery won't work
// 'method' => 'update', // Optional: Use 'clear' to truncate the table instead
],
// Add more tables as needed
],
];- tables: An array of tables to obfuscate
- columns: (Optional, can be omitted when the table needs to be cleared) The columns to obfuscate and the obfuscation method to use. Only columns that should be obfuscated need to be specified.
- chunk_size: (Optional) The number of records to process at once (default: 2000). See Performance Considerations
- keys: (Optional) The key columns to use. The key columns are discovered when obfuscating, but if that fails (for example when there are no primary keys) the unique 'key' can be specified.
- method: (Optional) The method to use for obfuscation (default: 'update', alternative: 'clear' to clear the table. This can be useful for tables like
jobsor tables that store audit logs.)
To obfuscate your database, run the following command:
php artisan blur:obfuscate
⚠️ This will change records (as you configured) for the default database connection.
You can use the interactive mode to select which tables to obfuscate:
php artisan blur:obfuscate --interactive
# or
php artisan blur:obfuscate -iThis will display a list of configured tables and allow you to select which ones to obfuscate.
Blur comes with built-in support for Faker. You can use any Faker method by prefixing it with faker::
'columns' => [
'name' => 'faker:name',
'email' => 'faker:email',
'phone' => 'faker:phoneNumber',
'address' => 'faker:address',
// See Faker documentation for more available methods
],You can create your own obfuscators by implementing the Intermax\Blur\Contracts\Obfuscator interface:
<?php
namespace App\Obfuscators;
use Intermax\Blur\Contracts\Obfuscator;
class FixedStringObfuscator implements Obfuscator
{
public function generate(?array $parameters = null): mixed
{
return $parameters[0] ?? 'default-value';
}
}Then use it in your configuration:
'columns' => [
'some_field' => App\Obfuscators\FixedStringObfuscator::class.':custom-value',
],Blur processes records in chunks. You can adjust the chunk_size in the configuration to balance between memory usage and performance.
The MIT License (MIT). Please see License File for more information.
Contributions are welcome! Please feel free to submit a Pull Request.