@@ -49,8 +49,15 @@ use Tobyz\JsonApiServer\Laravel\EloquentResource;
49
49
50
50
class PostsResource extends EloquentResource
51
51
{
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
+ }
54
61
55
62
public function endpoints(): array
56
63
{
@@ -117,11 +124,11 @@ requests, and force delete a resource using a `DELETE` request.
117
124
118
125
To expose the soft-delete capability to the client, add the
119
126
` 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:
121
128
122
129
``` php
123
- use Tobyz\JsonApiServer\Laravel\Fields\SoftDelete; // [!code ++]
124
130
use Tobyz\JsonApiServer\Laravel\SoftDeletes; // [!code ++]
131
+ use Tobyz\JsonApiServer\Schema\Field\DateTime; // [!code ++]
125
132
126
133
class PostsResource extends EloquentResource
127
134
{
@@ -132,20 +139,22 @@ class PostsResource extends EloquentResource
132
139
public function fields(): array
133
140
{
134
141
return [
135
- SoftDelete ::make('deletedAt'), // [!code ++]
142
+ DateTime ::make('deletedAt')->nullable( ), // [!code ++]
136
143
];
137
144
}
138
145
}
139
146
```
140
147
141
148
If 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 :
144
151
145
152
``` php
146
- SoftDelete::make('isDeleted')
153
+ use Tobyz\JsonApiServer\Schema\Field\BooleanDateTime;
154
+
155
+ BooleanDateTime::make('isDeleted')
147
156
->property('deleted_at')
148
- ->asBoolean ();
157
+ ->writable ();
149
158
```
150
159
151
160
## Filters
@@ -156,8 +165,12 @@ resources.
156
165
### Where
157
166
158
167
``` php
159
- Where::make('id');
160
168
Where::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');
161
174
WhereHas::make('comments');
162
175
WhereDoesntHave::make('comments');
163
176
WhereNull::make('draft')->property('published_at');
0 commit comments