Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeccanici committed Sep 21, 2023
1 parent a6ab689 commit a0b5bf6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/working-with-states/01-configuring-states.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ abstract class PaymentState extends State
}
```

### Registering custom StateChanged event
By default, when a state is changed, the `StateChanged` event is fired. If you want to use a custom event, you can register it in the `config` method:

```php
use Spatie\ModelStates\State;
use Spatie\ModelStates\StateConfig;

use Your\Concrete\State\Event\CustomStateChanged;

abstract class PaymentState extends State
{
abstract public function color(): string;

public static function config(): StateConfig
{
return parent::config()
->stateChangedEvent(CustomStateChanged::class)
;
}
}
```
## Configuring states using attributes

If you're using PHP 8 or higher, you can also configure your state using attributes:
Expand Down

0 comments on commit a0b5bf6

Please sign in to comment.