Skip to content

Commit fd9fdbd

Browse files
committed
[Docs] Update validators chapter and upgrade guide
1 parent 291ddee commit fd9fdbd

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. This projec
55
## Unreleased
66

77
### Changed
8+
- [#497](https://github.com/cloudcreativity/laravel-json-api/issues/497) and
9+
[#529](https://github.com/cloudcreativity/laravel-json-api/pull/529)
10+
**BREAKING:** The method signature of the `AbstractValidators::rules()` method has changed,
11+
so that the method has access to the data that will be validated.
812
- [#393](https://github.com/cloudcreativity/laravel-json-api/issues/393)
913
**BREAKING:** when using the `SoftDeletesModel` trait on an adapter, the expected JSON API field
1014
for the soft delete attribute now defaults to the camel-case version of the model column. For example,

docs/basics/validators.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ class Validators extends AbstractValidators
111111
*
112112
* @param mixed|null $record
113113
* the record being updated, or null if creating a resource.
114+
* @param array $data
115+
* the data being validated.
114116
* @return mixed
115117
*/
116-
protected function rules($record = null): array
118+
protected function rules($record, array $data): array
117119
{
118120
return [
119121
//
@@ -218,7 +220,7 @@ class Validators extends AbstractValidators
218220
{
219221
// ...
220222

221-
protected function rules($record = null): array
223+
protected function rules($record, array $data): array
222224
{
223225
return [
224226
'title' => 'required|string|min:1|max:255',
@@ -239,7 +241,7 @@ This is because the package complies with the JSON API spec and validates all re
239241
check that they exist. Therefore the following **does not** need to be used:
240242

241243
```php
242-
protected function rules($record = null): array
244+
protected function rules($record, array $data): array
243245
{
244246
return [
245247
'author.id' => 'exists:users,id',
@@ -253,7 +255,7 @@ type is provided to the constructor, then the plural form of the attribute name
253255
example:
254256

255257
```php
256-
protected function rules($record = null): array
258+
protected function rules($record, array $data): array
257259
{
258260
return [
259261
'author' => [
@@ -386,7 +388,7 @@ class Validators extends AbstractValidators
386388
{
387389
// ...
388390

389-
protected function rules($record = null): array
391+
protected function rules($record, array $data): array
390392
{
391393
return [
392394
'title' => "required|string|min:3",
@@ -925,7 +927,7 @@ class Validators extends AbstractValidators
925927
{
926928
// ...
927929

928-
protected function rules($record = null): array
930+
protected function rules($record, array $data): array
929931
{
930932
return [
931933
'name' => 'required|string',
@@ -962,7 +964,7 @@ class Validators extends AbstractValidators
962964
return $validator;
963965
}
964966

965-
protected function rules($record = null): array
967+
protected function rules($record, array $data): array
966968
{
967969
$rules = [
968970
'name' => 'required|string',

docs/upgrade.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
## 2.x to 3.0
44

5+
### Validators
6+
7+
The method signature of the `rules()` method has changed so that the method has access to the data
8+
that is going to be validated. You will need to amend the method signature on all of your validator
9+
classes.
10+
11+
The method signature was previously:
12+
13+
```
14+
protected function rules($record = null): array
15+
{
16+
// ...
17+
}
18+
```
19+
20+
It is now:
21+
22+
```
23+
protected function rules($record, array $data): array
24+
{
25+
// ...
26+
}
27+
```
28+
529
### Soft Deletes
630

731
Previously if no soft deletes field was set on an adapter, the JSON API field would default to the dash-case

0 commit comments

Comments
 (0)