@@ -36,7 +36,7 @@ class UserResource extends StatefulJsonResource
36
36
37
37
## Built-in States
38
38
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:
40
40
41
41
- ** ` Full ` ** - For all available attributes
42
42
- ** ` Table ` ** - For attributes suitable for table/listing views
@@ -53,7 +53,7 @@ Inside your stateful resource, you can use conditional methods to control which
53
53
54
54
namespace App\Http\Resources;
55
55
56
- use Farbcode\StatefulResources\Enums\Variant ;
56
+ use Farbcode\StatefulResources\Enums\State ;
57
57
use Farbcode\StatefulResources\StatefulJsonResource;
58
58
use Illuminate\Http\Request;
59
59
@@ -64,14 +64,14 @@ class UserResource extends StatefulJsonResource
64
64
return [
65
65
'id' => $this->id,
66
66
'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], [
69
69
'bio' => $this->bio,
70
70
'avatar' => $this->avatar,
71
71
'created_at' => $this->created_at,
72
72
]),
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),
75
75
];
76
76
}
77
77
}
@@ -93,24 +93,24 @@ The package provides several methods to conditionally include attributes:
93
93
Include a value only when the current state matches the specified state:
94
94
95
95
``` 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'),
98
98
```
99
99
100
100
### ` unlessState `
101
101
102
102
Include a value unless the current state matches the specified state:
103
103
104
104
``` php
105
- 'public_info' => $this->unlessState(Variant ::Minimal, $this->public_information),
105
+ 'public_info' => $this->unlessState(State ::Minimal, $this->public_information),
106
106
```
107
107
108
108
### ` whenStateIn `
109
109
110
110
Include a value when the current state is one of the specified states:
111
111
112
112
``` php
113
- 'detailed_info' => $this->whenStateIn([Variant ::Full, Variant ::Table], [
113
+ 'detailed_info' => $this->whenStateIn([State ::Full, State ::Table], [
114
114
'department' => $this->department,
115
115
'position' => $this->position,
116
116
]),
@@ -121,7 +121,7 @@ Include a value when the current state is one of the specified states:
121
121
Include a value unless the current state is one of the specified states:
122
122
123
123
``` 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),
125
125
```
126
126
127
127
### Magic Conditionals
@@ -140,15 +140,15 @@ You can also use magic methods with for cleaner syntax:
140
140
Use the static ` state() ` method to create a resource with a specific state:
141
141
142
142
``` php
143
- $user = UserResource::state(Variant ::Minimal)->make($user);
143
+ $user = UserResource::state(State ::Minimal)->make($user);
144
144
```
145
145
146
146
### Using Magic Methods
147
147
148
148
You can also use magic methods for a more fluent syntax:
149
149
150
150
``` php
151
- // This is equivalent to the explicit state() call
151
+ // This is equivalent to the explicit state(State::Minimal ) call
152
152
$user = UserResource::minimal()->make($user);
153
153
```
154
154
0 commit comments