@@ -7,6 +7,10 @@ This package allows you to register custom states that you can then use in your
77
88Before 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
1216use 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)
7983UserResource::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