You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/basics/validators.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -203,6 +203,35 @@ Your validator will be provided with the following array of data:
203
203
];
204
204
```
205
205
206
+
### Basic Rule Example
207
+
208
+
The following is an example query rule for the above-mentioned data:
209
+
210
+
```php
211
+
protected function rules($record = null): array
212
+
{
213
+
return [
214
+
'title' => 'required|string|min:1|max:255',
215
+
'content' => 'required|string|min:1',
216
+
'author.type' => 'in:users',
217
+
'tags.*.type' => 'in:tags',
218
+
];
219
+
}
220
+
221
+
```
222
+
223
+
You'll notice that 'exists' is not used in the validation. This is because the package complies to the JSON API spec and validates if the record exists. Hence the following should **NOT** be used:
224
+
225
+
```php
226
+
protected function rules($record = null): array
227
+
{
228
+
return [
229
+
'author.id' => 'exists:users,id',
230
+
'tags.*.id' => 'exists:tags,id'
231
+
];
232
+
}
233
+
```
234
+
206
235
### Updating Resources
207
236
208
237
When updating resources, the JSON API specification says:
0 commit comments