- 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.