Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphjsmit committed Jan 23, 2023
1 parent 471270b commit 26dbcbe
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions docs/working-with-states/01-configuring-states.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,6 @@ abstract class PaymentState extends State
}
```

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

```php
use Spatie\ModelStates\Attributes\AllowTransition;
use Spatie\ModelStates\State;

#[
AllowTransition(Pending::class, Paid::class),
AllowTransition(Pending::class, Failed::class),
DefaultState(Pending::class),
]
abstract class PaymentState extends State
{
abstract public function color(): string;
}
```

## Manually registering states
If you want to place your concrete state implementations in a different directory, you may do so and register them manually:

Expand Down Expand Up @@ -128,4 +111,25 @@ abstract class PaymentState extends State
}
```

## Configuring states using attributes

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

```php
use Spatie\ModelStates\Attributes\AllowTransition;
use Spatie\ModelStates\Attributes\RegisterState;use Spatie\ModelStates\State;use const Grpc\STATUS_CANCELLED;

#[
AllowTransition(Pending::class, Paid::class),
AllowTransition(Pending::class, Failed::class),
DefaultState(Pending::class),
RegisterState(Cancelled::class),
RegisterState([ExampleOne::class, ExampleTwo::class]),
]
abstract class PaymentState extends State
{
abstract public function color(): string;
}
```

Next up, we'll take a moment to discuss how state classes are serialized to the database.

0 comments on commit 26dbcbe

Please sign in to comment.