Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Anonymize Laravel Package

directorytree/anonymize

Anonymize swaps sensitive Eloquent model attributes with realistic Faker data. Deterministic per model ID, cached for performance, and easy to toggle globally or per instance—ideal for dev, demos, and safely sharing production-like datasets.

View on GitHub
Deep Wiki
Context7

directorytree/anonymize helps you anonymize sensitive Eloquent model attributes using realistic Faker data—ideal for development, demos, and sharing production-like datasets without exposing PII. It swaps selected fields transparently while preserving your app’s data shape and relationships.

Enable anonymization globally or per model instance, and define exactly which attributes to mask via an Anonymizable interface + Anonymized trait.

  • Privacy-first masking of chosen attributes
  • Deterministic fakes: same model ID → same output
  • Seamless Eloquent integration (non-anonymized fields untouched)
  • Granular control (toggle globally or per instance)
  • Caching to avoid redundant fake generation
Frequently asked questions about Anonymize
How do I anonymize sensitive fields in a Laravel Eloquent model using this package?
Implement the `Anonymizable` interface and use the `Anonymized` trait in your model. Define which attributes to anonymize in the `getAnonymizedAttributes()` method, returning Faker-generated values for each field. Non-listed fields remain unchanged.
Can I enable anonymization globally for all models or just specific ones?
Yes, you can toggle anonymization globally via `Anonymize::enable()` or disable it with `Anonymize::disable()`. For granular control, enable it per model instance using `Anonymize::enableFor($model)`.
Does this package work with Laravel 13 and PHP 8.2+?
Yes, the package explicitly supports Laravel 11–13 and PHP 8.2+. Always check the latest version on Packagist for minor version compatibility updates.
Will anonymized data be consistent across requests for the same model ID?
Yes, the package uses deterministic seeding via `getAnonymizableSeed()`, ensuring the same model ID always generates identical fake data. This is ideal for testing and debugging.
How does caching work to improve performance?
The package caches anonymized data to avoid redundant Faker generation. This is especially useful for high-traffic APIs or large datasets. Caching is enabled by default and can be configured via the `Anonymize` facade.
Can I anonymize nested JSON resources (e.g., User with Orders) recursively?
Yes, the package supports nested resources via the `AnonymizedResource` trait. Ensure your child models (e.g., `Order`) also implement `Anonymizable` and `Anonymized` for full recursion.
What happens if I need custom fake data beyond Faker’s defaults?
Extend Faker globally using `Faker::extend()` before initializing the package. This allows you to add domain-specific fake data providers while maintaining compatibility with the package’s core functionality.
Is there a way to log or audit anonymization events in production?
Yes, the package dispatches `AnonymizeEnabled` and `AnonymizeDisabled` events. Listen to these events in your `EventServiceProvider` to log, monitor, or trigger additional logic like analytics.
How should I test anonymization in my Laravel application?
Use deterministic seeding for predictable test outputs. Enable anonymization in test cases via `Anonymize::enable()` and verify results by comparing anonymized attributes against expected Faker-generated values.
Are there alternatives to this package for Laravel model anonymization?
Alternatives include custom solutions using Faker directly or packages like `spatie/laravel-faker`. However, this package offers seamless Eloquent integration, deterministic caching, and granular control out of the box, making it ideal for production-like environments.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport