@@ -7,6 +7,10 @@ This package allows you to register custom states that you can then use in your
7
7
8
8
Before using a custom state, register it in the package's ` stateful-resources.states ` configuration:
9
9
10
+ ::: info
11
+ States should either be single words, snake_case, or kebab-case.
12
+ :::
13
+
10
14
``` php
11
15
<?php
12
16
use Farbcode\StatefulResources\Enums\State;
@@ -35,7 +39,7 @@ enum CustomResourceState: string implements ResourceState
35
39
{
36
40
case Compact = 'compact';
37
41
case Extended = 'extended';
38
- case Debug = 'debug ';
42
+ case DebugOnly = 'debug_only ';
39
43
}
40
44
```
41
45
@@ -59,7 +63,7 @@ class UserResource extends StatefulJsonResource
59
63
'id' => $this->id,
60
64
'name' => $this->name,
61
65
'email' => $this->whenState(CustomResourceState::Extended, $this->email),
62
- 'debug_info' => $this->whenStateDebug ([
66
+ 'debug_info' => $this->whenStateDebugOnly ([
63
67
'created_at' => $this->created_at,
64
68
'updated_at' => $this->updated_at,
65
69
]),
@@ -77,4 +81,7 @@ UserResource::state(CustomResourceState::Compact)->make($user);
77
81
78
82
// Using the magic method (if the state name matches the case name)
79
83
UserResource::compact()->make($user);
84
+
85
+ // States using snake_case or kebab-case can be called as camelCase
86
+ UserResource::debugOnly()->make($user);
80
87
```
0 commit comments