Download the PHP package directorytree/anonymize without Composer
On this page you can find all versions of the php package directorytree/anonymize. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download directorytree/anonymize
More information about directorytree/anonymize
Files in directorytree/anonymize
Package anonymize
Short Description Anonymize sensitive model data with realistic fake data using Faker
License MIT
Informations about the package anonymize
Anonymize
Replace sensitive Eloquent model attributes with realistic fake data.
Installation · Usage · Testing
Features
- Privacy-First: Automatically anonymize sensitive model attributes
- Consistent Data: Same model ID always generates the same fake data
- Seamless Integration: Works transparently with existing Eloquent models
- Granular Control: Enable/disable anonymization globally or per-model instance
- Performance Optimized: Intelligent caching prevents redundant fake data generation
Requirements
- PHP >= 8.2
- Laravel >= 11
Installation
Install the package with Composer:
Usage
Set Up Your Model
Implement the Anonymizable interface and use the Anonymized trait on your Eloquent model.
Then, define the attributes you want to anonymize in the getAnonymizedAttributes() method:
The attributes returned by getAnonymizedAttributes() will replace its original attributes when anonymization is enabled.
Attributes that are not defined in the getAnonymizedAttributes() will not be anonymized, and will be returned as-is.
Enable Anonymization
Somewhere within your application, enable anonymization:
[!note] This is typically done within a service provider or middleware, and controlled with a session variable.
Controlling Anonymization
Control anonymization across your application using the Anonymize facade:
Consistent Fake Data
Anonymize ensures that the same model always generates the same fake data.
This makes browsing your application consistent and predictable:
Different models generate different fake data:
Custom Seed Generation
Override the seed generation logic for more control.
The seed is used to ensure consistent fake data generation:
Conditional Anonymization
Only anonymize specific attributes based on conditions:
Anonymizing JSON Resources
You can also anonymize Laravel JSON resources by implementing the Anonymizable interface and using the AnonymizedResource trait:
When anonymization is enabled, the resource will automatically replace sensitive data in the JSON response:
Testing
Benchmarking
License
The MIT License (MIT). Please see License File for more information.