Skip to content

Commit 65595d6

Browse files
docs: update documentation for snake and kebab cased states
1 parent a5f5525 commit 65595d6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

docs/pages/extending-states.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ This package allows you to register custom states that you can then use in your
77

88
Before using a custom state, register it in the package's `stateful-resources.states` configuration:
99

10+
::: info
11+
States should either be single words, snake_case, or kebab-case.
12+
:::
13+
1014
```php
1115
<?php
1216
use Farbcode\StatefulResources\Enums\State;
@@ -35,7 +39,7 @@ enum CustomResourceState: string implements ResourceState
3539
{
3640
case Compact = 'compact';
3741
case Extended = 'extended';
38-
case Debug = 'debug';
42+
case DebugOnly = 'debug_only';
3943
}
4044
```
4145

@@ -59,7 +63,7 @@ class UserResource extends StatefulJsonResource
5963
'id' => $this->id,
6064
'name' => $this->name,
6165
'email' => $this->whenState(CustomResourceState::Extended, $this->email),
62-
'debug_info' => $this->whenStateDebug([
66+
'debug_info' => $this->whenStateDebugOnly([
6367
'created_at' => $this->created_at,
6468
'updated_at' => $this->updated_at,
6569
]),
@@ -77,4 +81,7 @@ UserResource::state(CustomResourceState::Compact)->make($user);
7781

7882
// Using the magic method (if the state name matches the case name)
7983
UserResource::compact()->make($user);
84+
85+
// States using snake_case or kebab-case can be called as camelCase
86+
UserResource::debugOnly()->make($user);
8087
```

0 commit comments

Comments
 (0)