Skip to content

Commit e30f122

Browse files
committed
Update README.md
1 parent f079240 commit e30f122

File tree

1 file changed

+9
-71
lines changed

1 file changed

+9
-71
lines changed

README.md

Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ composer require directorytree/anonymize
2424

2525
The package will automatically register its service provider.
2626

27-
## Quick Start
27+
## Usage
2828

2929
### Set Up Your Model
3030

@@ -56,6 +56,10 @@ class User extends Model implements Anonymizable
5656
}
5757
```
5858

59+
The attributes returned by `getAnonymizedAttributes()` will replace the original attributes when anonymization is enabled.
60+
61+
Attributes not defined in the `getAnonymizedAttributes()` will not be anonymized.
62+
5963
### Enable Anonymization
6064

6165
Somewhere within your application, enable anonymization:
@@ -77,11 +81,9 @@ class AppServiceProvider extends ServiceProvider
7781
}
7882
```
7983

80-
## Usage
81-
82-
### Global Control
84+
### Controlling Anonymization
8385

84-
Control anonymization across your entire application:
86+
Control anonymization across your application using the `Anonymize` facade:
8587

8688
```php
8789
use DirectoryTree\Anonymize\Facades\Anonymize;
@@ -98,22 +100,6 @@ if (Anonymize::isEnabled()) {
98100
}
99101
```
100102

101-
### Per-Model Control
102-
103-
Temporarily disable anonymization for specific operations:
104-
105-
```php
106-
$user = User::find(1);
107-
108-
// Get real data even when anonymization is globally enabled
109-
$realData = $user->withoutAnonymization(function ($model) {
110-
return $model->attributesToArray();
111-
});
112-
113-
// Or access individual attributes
114-
$realName = $user->withoutAnonymization(fn ($model) => $model->name);
115-
```
116-
117103
### Consistent Fake Data
118104

119105
Anonymize ensures that the same model always generates the same fake data.
@@ -142,9 +128,7 @@ $user1->name !== $user2->name; // true
142128
$user1->email !== $user2->email; // true
143129
```
144130

145-
### Advanced Configuration
146-
147-
#### Custom Seed Generation
131+
### Custom Seed Generation
148132

149133
Override the seed generation logic for more control.
150134

@@ -170,7 +154,7 @@ class User extends Model implements Anonymizable
170154
}
171155
```
172156

173-
#### Conditional Anonymization
157+
### Conditional Anonymization
174158

175159
Only anonymize specific attributes based on conditions:
176160

@@ -191,52 +175,6 @@ public function getAnonymizedAttributes(Generator $faker): array
191175
}
192176
```
193177

194-
### Environment-Based Usage
195-
196-
Perfect for different environments:
197-
198-
```php
199-
// In your AppServiceProvider or middleware
200-
if (app()->environment(['local', 'staging'])) {
201-
Anonymize::enable();
202-
}
203-
```
204-
205-
### API Resources
206-
207-
Works seamlessly with API resources:
208-
209-
```php
210-
class UserResource extends JsonResource
211-
{
212-
public function toArray($request)
213-
{
214-
return [
215-
'id' => $this->id,
216-
'name' => $this->name, // Will be anonymized if enabled
217-
'email' => $this->email, // Will be anonymized if enabled
218-
'created_at' => $this->created_at,
219-
];
220-
}
221-
}
222-
```
223-
224-
## How It Works
225-
226-
1. **Seeded Generation**: Each model generates a unique seed based on its class and ID
227-
2. **Consistent Output**: The same seed always produces the same fake data
228-
3. **Selective Replacement**: Only attributes defined in `getAnonymizedAttributes()` are replaced
229-
4. **Transparent Operation**: Works with `attributesToArray()`, `toArray()`, `toJson()`, and direct attribute access
230-
5. **Performance Optimized**: Fake data is cached per model instance to avoid regeneration
231-
232-
## Use Cases
233-
234-
- **Development Environments**: Work with realistic data without exposing sensitive information
235-
- **Demo Applications**: Show your app with convincing data that's not real
236-
- **Data Sharing**: Share database dumps with partners or team members safely
237-
- **Testing**: Create consistent test scenarios with predictable fake data
238-
- **Staging Environments**: Mirror production data structure without privacy concerns
239-
240178
## Performance
241179

242180
The package is designed for optimal performance:

0 commit comments

Comments
 (0)