Skip to content

Commit

Permalink
Update exclude function name and add reference to it in README
Browse files Browse the repository at this point in the history
  • Loading branch information
jared-cannon committed Jan 16, 2025
1 parent 32e5a06 commit c7960da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ That’s it! Now your model’s changes are recorded in the `rewind_versions` ta
// Jump directly to a specific version
Rewind::goTo($post, 5);
```
3. Excluding attributes from versioning

If you have attributes that you don't want to track, you can exclude them by adding an `excludedFromVersioning`
method to your model:

```php
public static function excludedFromVersioning(): array
{
return ['password', 'api_token'];
}
```

## Testing

Expand Down
7 changes: 5 additions & 2 deletions src/Traits/Rewindable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ protected function getExcludedRewindableAttributes(): array
'current_version',
];

return array_unique(array_merge($defaultExclusions, $this->excludeFromRewindable()));
return array_unique(array_merge($defaultExclusions, $this->excludedFromVersioning()));
}

public static function excludeFromRewindable(): array
/**
* Define any additional attributes to exclude from rewind's versions.
*/
public static function excludedFromVersioning(): array
{
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/PostWithExcludedAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PostWithExcludedAttributes extends Model
'body',
];

public static function excludeFromRewindable(): array
public static function excludedFromVersioning(): array
{
return ['body'];
}
Expand Down

0 comments on commit c7960da

Please sign in to comment.