Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
asantibanez committed Feb 13, 2021
1 parent 73bc50b commit f2a70b5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

All notable changes to `laravel-eloquent-state-machines` will be documented in this file

## v4.0.0 - 2021-02-12

- Added `changed_attributes` field in `state_histories` to record model old/new
values during transition (**Breaking change**)

## v3.0.0 - 2021-02-10

- Added `beforeTransitionHooks`
- **Breaking Change**: Renamed `transitionHooks` to `afterTransitionHooks` and changed arguments for callbacks
- Renamed `transitionHooks` to `afterTransitionHooks` and changed arguments for callbacks (**Breaking Change**)
- Refactored tests

## v2.3.0 - 2020-01-26
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,29 @@ $salesOrder->status()->snapshotWhen('approved')->responsible;
## Advanced Usage

### Tracking Attribute Changes

When `recordHistory()` is active, model state transitions are recorded in the `state_histories` table. Each transition
record contains information about the attributes that changed during the state transition. You can get information
about what has changed via the `changedAttributesNames()` method. This method will return an array of the attributes
names that changed. With these attributes names, you can then use the methods `changedAttributeOldValue($attributeName)`
and `changedAttributeNewValue($attributeName)` to get the old and new values respectively.

```php
$salesOrder = SalesOrder::create([
'total' => 100,
]);

$salesOrder->total = 200;

$salesOrder->status()->transitionTo('approved');

$salesOrder->changedAttributesNames(); // ['total']

$salesOrder->changedAttributeOldValue('total'); // 100
$salesOrder->changedAttributeNewValue('total'); // 200
```

### Adding Validations

Before transitioning to a new state, we can add validations that will allow/disallow the transition. To
Expand Down

0 comments on commit f2a70b5

Please sign in to comment.