@@ -49,8 +49,15 @@ use Tobyz\JsonApiServer\Laravel\EloquentResource;
4949
5050class PostsResource extends EloquentResource
5151{
52- public readonly string $type = 'posts';
53- public readonly string $model = Post::class;
52+ public function type(): string
53+ {
54+ return 'posts';
55+ }
56+
57+ public function newModel(Context $context): object
58+ {
59+ return new Post();
60+ }
5461
5562 public function endpoints(): array
5663 {
@@ -117,11 +124,11 @@ requests, and force delete a resource using a `DELETE` request.
117124
118125To expose the soft-delete capability to the client, add the
119126` Tobyz\JsonApiServer\Laravel\SoftDeletes ` trait to your Eloquent resource, and a
120- ` Tobyz\JsonApiServer\Laravel\Fields\SoftDelete ` field to your fields array:
127+ nullable ` DateTime ` field to your fields array:
121128
122129``` php
123- use Tobyz\JsonApiServer\Laravel\Fields\SoftDelete; // [!code ++]
124130use Tobyz\JsonApiServer\Laravel\SoftDeletes; // [!code ++]
131+ use Tobyz\JsonApiServer\Schema\Field\DateTime; // [!code ++]
125132
126133class PostsResource extends EloquentResource
127134{
@@ -132,20 +139,22 @@ class PostsResource extends EloquentResource
132139 public function fields(): array
133140 {
134141 return [
135- SoftDelete ::make('deletedAt'), // [!code ++]
142+ DateTime ::make('deletedAt')->nullable( ), // [!code ++]
136143 ];
137144 }
138145}
139146```
140147
141148If you prefer to use a boolean to indicate whether or not a resource is
142- soft-deleted instead of a nullable date-time value, you can call the ` asBoolean `
143- method on the ` SoftDelete ` field:
149+ soft-deleted instead of a nullable date-time value, you can use a
150+ ` BooleanDateTime ` field instead :
144151
145152``` php
146- SoftDelete::make('isDeleted')
153+ use Tobyz\JsonApiServer\Schema\Field\BooleanDateTime;
154+
155+ BooleanDateTime::make('isDeleted')
147156 ->property('deleted_at')
148- ->asBoolean ();
157+ ->writable ();
149158```
150159
151160## Filters
@@ -156,8 +165,12 @@ resources.
156165### Where
157166
158167``` php
159- Where::make('id');
160168Where::make('name');
169+ Where::make('id')->commaSeparated();
170+ Where::make('isConfirmed')->asBoolean();
171+ Where::make('score')->asNumeric();
172+ WhereBelongsTo::make('user');
173+ Has::make('hasComments');
161174WhereHas::make('comments');
162175WhereDoesntHave::make('comments');
163176WhereNull::make('draft')->property('published_at');
0 commit comments