@@ -73,7 +73,7 @@ class PostsResource extends EloquentResource
7373 public function fields(): array
7474 {
7575 return [
76- Field\Str ::make('title'),
76+ Field\Attribute ::make('title'),
7777 Field\ToOne::make('author')->type('users'),
7878 ];
7979 }
@@ -124,11 +124,13 @@ requests, and force delete a resource using a `DELETE` request.
124124
125125To expose the soft-delete capability to the client, add the
126126` Tobyz\JsonApiServer\Laravel\SoftDeletes ` trait to your Eloquent resource, and a
127- nullable ` DateTime ` field to your fields array:
127+ nullable [ ` DateTime ` field] ( attributes.md#date-and-datetime ) to your fields
128+ array:
128129
129130``` php
130131use Tobyz\JsonApiServer\Laravel\SoftDeletes; // [!code ++]
131- use Tobyz\JsonApiServer\Schema\Field\DateTime; // [!code ++]
132+ use Tobyz\JsonApiServer\Schema\Field\Attribute; // [!code ++]
133+ use Tobyz\JsonApiServer\Schema\Type\DateTime; // [!code ++]
132134
133135class PostsResource extends EloquentResource
134136{
@@ -139,15 +141,17 @@ class PostsResource extends EloquentResource
139141 public function fields(): array
140142 {
141143 return [
142- DateTime::make('deletedAt')->nullable(), // [!code ++]
144+ Attribute::make('deletedAt') // [!code ++]
145+ ->type(DateTime::make()), // [!code ++]
146+ ->nullable(), // [!code ++]
143147 ];
144148 }
145149}
146150```
147151
148152If you prefer to use a boolean to indicate whether or not a resource is
149153soft-deleted instead of a nullable date-time value, you can use a
150- ` BooleanDateTime ` field instead:
154+ [ ` BooleanDateTime ` attribute ] ( attributes.md#booleandatetime ) instead:
151155
152156``` php
153157use Tobyz\JsonApiServer\Schema\Field\BooleanDateTime;
@@ -290,7 +294,7 @@ rules to be applied to the value:
290294``` php
291295use function Tobyz\JsonApiServer\Laravel\rules;
292296
293- Str ::make('password')->validate(rules(['password']));
297+ Attribute ::make('password')->validate(rules(['password']));
294298```
295299
296300Note that values are validated one at a time, so interdependent rules such as
@@ -300,23 +304,17 @@ You can add an `{id}` placeholder to database rules such as `unique` which will
300304be substituted if a model is being updated:
301305
302306``` php
303- Str ::make('email')
304- ->format('email')
307+ Attribute ::make('email')
308+ ->type(Str::make()-> format('email') )
305309 ->validate(Laravel\rules(['email', 'unique:users,email,{id}']));
306310```
307311
308312Validating array contents is also supported:
309313
310314``` php
311- $type
312- ->attribute('jobs')
313- ->validate(
314- Laravel\rules([
315- 'required',
316- 'array',
317- '*' => ['string', 'min:3', 'max:255'],
318- ]),
319- );
315+ Attribute::make('jobs')->validate(
316+ Laravel\rules(['required', 'array', '*' => ['string', 'min:3', 'max:255']]),
317+ );
320318```
321319
322320You can also pass an array of custom messages and custom attribute names as the
0 commit comments