PHP code example of outsidaz / laravel-data-anonymization
1. Go to this page and download the library: Download outsidaz/laravel-data-anonymization 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/ */
outsidaz / laravel-data-anonymization example snippets
return [
'locale' => 'en_US',
'chunk_size' => 1000,
'models_path' => app_path('Models'),
'models_namespace' => '\\App\\Models',
]
class User extends Authenticatable
{
use Anonymizable;
<...>
public function anonymizableAttributes(Generator $faker): array
{
return [
'email' => $this->id . '@custom.dev',
'password' => 'secret',
'firstname' => $faker->firstName(),
'surname' => $faker->lastName(),
'phone' => $faker->e164PhoneNumber(),
'position' => $faker->jobTitle(),
'token' => null,
];
}
// optional
public function anonymizableCondition(): Builder
{
return self::withTrashed()->where('something', '=>', '...');
}
}
class UserFactory extends Factory
{
public function definition(): array
{
return [
'email' => $this->faker()->numberBetween(1, 100_000) . '@custom.dev',
'password' => 'secret',
'firstname' => $this->faker->firstName(),
'surname' => $this->faker->lastName(),
'phone' => $this->faker->e164PhoneNumber(),
'position' => $this->faker->jobTitle(),
'token' => null,
]
}
public function anonymizableAttributes(): array
{
return [
'email',
'password',
'firstname',
'surname',
'phone',
'position',
'token',
]
}
}
class UserFactory extends Factory
{
public function definition(): array
{
return [
'email' => $this->faker()->numberBetween(1, 100_000) . '@custom.dev',
'password' => 'secret',
'firstname' => $faker->firstName(),
'surname' => $faker->lastName(),
'phone' => $faker->e164PhoneNumber(),
'position' => $faker->jobTitle(),
'token' => null,
]
}
public function anonymizableDefinition(): array
{
return [
'email' => $this->faker()->numberBetween(1, 100_000) . '@custom.dev',
'password' => 'secret',
'firstname' => $faker->firstName(),
'surname' => $faker->lastName(),
'phone' => $faker->e164PhoneNumber(),
'position' => $faker->jobTitle(),
'token' => $this->faker->md5(),
]
}
}
class UserFactory extends Factory
{
public function definition(): array
{
return [
'email' => $this->faker()->numberBetween(1, 100_000) . '@custom.dev',
'password' => 'secret',
'firstname' => $faker->firstName(),
'surname' => $faker->lastName(),
'phone' => $faker->e164PhoneNumber(),
'position' => $faker->jobTitle(),
'token' => null,
]
}
public function anonymizableAttributes(): array
{
return [
'email',
'password',
'firstname',
'surname',
'phone',
'position',
]
}
public function anonymizableDefinition(): array
{
return [
'token' => $this->faker->md5(),
]
}
}
bash
php artisan db:anonymize