@@ -36,7 +36,7 @@ class UserResource extends StatefulJsonResource
3636
3737## Built-in States
3838
39- The package comes with three built-in states defined in the ` Variant ` enum:
39+ The package comes with three built-in states defined in the ` State ` enum:
4040
4141- ** ` Full ` ** - For all available attributes
4242- ** ` Table ` ** - For attributes suitable for table/listing views
@@ -53,7 +53,7 @@ Inside your stateful resource, you can use conditional methods to control which
5353
5454namespace App\Http\Resources;
5555
56- use Farbcode\StatefulResources\Enums\Variant ;
56+ use Farbcode\StatefulResources\Enums\State ;
5757use Farbcode\StatefulResources\StatefulJsonResource;
5858use Illuminate\Http\Request;
5959
@@ -64,14 +64,14 @@ class UserResource extends StatefulJsonResource
6464 return [
6565 'id' => $this->id,
6666 'name' => $this->name,
67- 'email' => $this->whenState(Variant ::Full, $this->email),
68- 'profile' => $this->whenStateIn([Variant ::Full], [
67+ 'email' => $this->whenState(State ::Full, $this->email),
68+ 'profile' => $this->whenStateIn([State ::Full], [
6969 'bio' => $this->bio,
7070 'avatar' => $this->avatar,
7171 'created_at' => $this->created_at,
7272 ]),
73- 'role' => $this->whenStateIn([Variant ::Full, Variant ::Table], $this->role),
74- 'last_login' => $this->unlessState(Variant ::Minimal, $this->last_login_at),
73+ 'role' => $this->whenStateIn([State ::Full, State ::Table], $this->role),
74+ 'last_login' => $this->unlessState(State ::Minimal, $this->last_login_at),
7575 ];
7676 }
7777}
@@ -93,24 +93,24 @@ The package provides several methods to conditionally include attributes:
9393Include a value only when the current state matches the specified state:
9494
9595``` php
96- 'email' => $this->whenState(Variant ::Full, $this->email),
97- 'admin_notes' => $this->whenState(Variant ::Full, $this->admin_notes, 'N/A'),
96+ 'email' => $this->whenState(State ::Full, $this->email),
97+ 'admin_notes' => $this->whenState(State ::Full, $this->admin_notes, 'N/A'),
9898```
9999
100100### ` unlessState `
101101
102102Include a value unless the current state matches the specified state:
103103
104104``` php
105- 'public_info' => $this->unlessState(Variant ::Minimal, $this->public_information),
105+ 'public_info' => $this->unlessState(State ::Minimal, $this->public_information),
106106```
107107
108108### ` whenStateIn `
109109
110110Include a value when the current state is one of the specified states:
111111
112112``` php
113- 'detailed_info' => $this->whenStateIn([Variant ::Full, Variant ::Table], [
113+ 'detailed_info' => $this->whenStateIn([State ::Full, State ::Table], [
114114 'department' => $this->department,
115115 'position' => $this->position,
116116]),
@@ -121,7 +121,7 @@ Include a value when the current state is one of the specified states:
121121Include a value unless the current state is one of the specified states:
122122
123123``` php
124- 'sensitive_data' => $this->unlessStateIn([Variant ::Minimal, Variant ::Table], $this->sensitive_info),
124+ 'sensitive_data' => $this->unlessStateIn([State ::Minimal, State ::Table], $this->sensitive_info),
125125```
126126
127127### Magic Conditionals
@@ -140,15 +140,15 @@ You can also use magic methods with for cleaner syntax:
140140Use the static ` state() ` method to create a resource with a specific state:
141141
142142``` php
143- $user = UserResource::state(Variant ::Minimal)->make($user);
143+ $user = UserResource::state(State ::Minimal)->make($user);
144144```
145145
146146### Using Magic Methods
147147
148148You can also use magic methods for a more fluent syntax:
149149
150150``` php
151- // This is equivalent to the explicit state() call
151+ // This is equivalent to the explicit state(State::Minimal ) call
152152$user = UserResource::minimal()->make($user);
153153```
154154
0 commit comments