Skip to content

Commit 131fd8e

Browse files
authored
Merge pull request #224 from RonasIT/206_correct_rules_generation
refactor: correct rules generation
2 parents 6592606 + 954b185 commit 131fd8e

File tree

8 files changed

+15
-15
lines changed

8 files changed

+15
-15
lines changed

src/Generators/RequestsGenerator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ protected function getSearchValidationParameters(): array
135135
'per_page',
136136
]);
137137

138-
$parameters['array'] = ['with'];
139-
140138
$parameters['string'] = ['order_by'];
141139

142140
$parameters['string-nullable'] = ['query'];
143141

142+
$parameters['array'] = ['with'];
143+
144144
$parameters['string-required'] = ['with.*'];
145145

146-
return $this->getValidationParameters($parameters, false);
146+
return $this->getValidationParameters($parameters, true);
147147
}
148148

149149
public function getValidationParameters($parameters, $requiredAvailable): array
@@ -187,7 +187,7 @@ protected function getRules($name, $type, $required, $nullable, $present): array
187187
}
188188

189189
if ($required) {
190-
$rules[] = 'required';
190+
array_unshift($rules, 'required');
191191
}
192192

193193
if ($nullable) {

tests/fixtures/CommandTest/get_request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function rules(): array
1414

1515
return [
1616
'with' => 'array',
17-
'with.*' => 'string|required|in:' . $availableRelations,
17+
'with.*' => 'required|string|in:' . $availableRelations,
1818
];
1919
}
2020

tests/fixtures/CommandTest/search_request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public function rules(): array
1717
'order_by' => 'string|in:' . $this->getOrderableFields(Post::class),
1818
'desc' => 'boolean',
1919
'all' => 'boolean',
20-
'with' => 'array',
2120
'query' => 'string|nullable',
22-
'with.*' => 'string|in:' . $availableRelations,
21+
'with' => 'array',
22+
'with.*' => 'required|string|in:' . $availableRelations,
2323
];
2424
}
2525

tests/fixtures/CommandTest/search_request_subfolder_model.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public function rules(): array
1717
'order_by' => 'string|in:' . $this->getOrderableFields(Post::class),
1818
'desc' => 'boolean',
1919
'all' => 'boolean',
20-
'with' => 'array',
2120
'query' => 'string|nullable',
22-
'with.*' => 'string|in:' . $availableRelations,
21+
'with' => 'array',
22+
'with.*' => 'required|string|in:' . $availableRelations,
2323
];
2424
}
2525

tests/fixtures/RequestGeneratorTest/create_request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class CreatePostRequest extends Request
99
public function rules(): array
1010
{
1111
return [
12-
'user_id' => 'integer|exists:users,id|required',
12+
'user_id' => 'required|integer|exists:users,id',
1313
'is_draft' => 'boolean',
1414
'is_published' => 'boolean|present',
1515
];

tests/fixtures/RequestGeneratorTest/get_request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function rules(): array
1414

1515
return [
1616
'with' => 'array',
17-
'with.*' => 'string|required|in:' . $availableRelations,
17+
'with.*' => 'required|string|in:' . $availableRelations,
1818
];
1919
}
2020

tests/fixtures/RequestGeneratorTest/search_request.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ public function rules(): array
1212
$availableRelations = implode(',', $this->getAvailableRelations());
1313

1414
return [
15-
'user_id' => 'integer|exists:users,id|required',
15+
'user_id' => 'required|integer|exists:users,id',
1616
'page' => 'integer',
1717
'per_page' => 'integer',
1818
'is_published' => 'boolean',
1919
'desc' => 'boolean',
2020
'all' => 'boolean',
21-
'with' => 'array',
2221
'order_by' => 'string|in:' . $this->getOrderableFields(Post::class),
2322
'query' => 'string|nullable',
24-
'with.*' => 'string|in:' . $availableRelations,
23+
'with' => 'array',
24+
'with.*' => 'required|string|in:' . $availableRelations,
2525
];
2626
}
2727

tests/fixtures/RequestGeneratorTest/update_request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class UpdatePostRequest extends Request
1111
public function rules(): array
1212
{
1313
return [
14-
'user_id' => 'integer|exists:users,id|required',
14+
'user_id' => 'required|integer|exists:users,id',
1515
'is_draft' => 'boolean',
1616
'is_published' => 'boolean',
1717
];

0 commit comments

Comments
 (0)