diff --git a/src/Generators/RequestsGenerator.php b/src/Generators/RequestsGenerator.php index 61219493..3bc939b6 100644 --- a/src/Generators/RequestsGenerator.php +++ b/src/Generators/RequestsGenerator.php @@ -135,15 +135,15 @@ protected function getSearchValidationParameters(): array 'per_page', ]); - $parameters['array'] = ['with']; - $parameters['string'] = ['order_by']; $parameters['string-nullable'] = ['query']; + $parameters['array'] = ['with']; + $parameters['string-required'] = ['with.*']; - return $this->getValidationParameters($parameters, false); + return $this->getValidationParameters($parameters, true); } public function getValidationParameters($parameters, $requiredAvailable): array @@ -187,7 +187,7 @@ protected function getRules($name, $type, $required, $nullable, $present): array } if ($required) { - $rules[] = 'required'; + array_unshift($rules, 'required'); } if ($nullable) { diff --git a/tests/fixtures/CommandTest/get_request.php b/tests/fixtures/CommandTest/get_request.php index 0f3e2bd2..f3baadfc 100644 --- a/tests/fixtures/CommandTest/get_request.php +++ b/tests/fixtures/CommandTest/get_request.php @@ -14,7 +14,7 @@ public function rules(): array return [ 'with' => 'array', - 'with.*' => 'string|required|in:' . $availableRelations, + 'with.*' => 'required|string|in:' . $availableRelations, ]; } diff --git a/tests/fixtures/CommandTest/search_request.php b/tests/fixtures/CommandTest/search_request.php index a6c6c801..fdfb22ba 100644 --- a/tests/fixtures/CommandTest/search_request.php +++ b/tests/fixtures/CommandTest/search_request.php @@ -17,9 +17,9 @@ public function rules(): array 'order_by' => 'string|in:' . $this->getOrderableFields(Post::class), 'desc' => 'boolean', 'all' => 'boolean', - 'with' => 'array', 'query' => 'string|nullable', - 'with.*' => 'string|in:' . $availableRelations, + 'with' => 'array', + 'with.*' => 'required|string|in:' . $availableRelations, ]; } diff --git a/tests/fixtures/CommandTest/search_request_subfolder_model.php b/tests/fixtures/CommandTest/search_request_subfolder_model.php index ff7dc4ec..3f864526 100644 --- a/tests/fixtures/CommandTest/search_request_subfolder_model.php +++ b/tests/fixtures/CommandTest/search_request_subfolder_model.php @@ -17,9 +17,9 @@ public function rules(): array 'order_by' => 'string|in:' . $this->getOrderableFields(Post::class), 'desc' => 'boolean', 'all' => 'boolean', - 'with' => 'array', 'query' => 'string|nullable', - 'with.*' => 'string|in:' . $availableRelations, + 'with' => 'array', + 'with.*' => 'required|string|in:' . $availableRelations, ]; } diff --git a/tests/fixtures/RequestGeneratorTest/create_request.php b/tests/fixtures/RequestGeneratorTest/create_request.php index 122aefdb..683422fa 100644 --- a/tests/fixtures/RequestGeneratorTest/create_request.php +++ b/tests/fixtures/RequestGeneratorTest/create_request.php @@ -9,7 +9,7 @@ class CreatePostRequest extends Request public function rules(): array { return [ - 'user_id' => 'integer|exists:users,id|required', + 'user_id' => 'required|integer|exists:users,id', 'is_draft' => 'boolean', 'is_published' => 'boolean|present', ]; diff --git a/tests/fixtures/RequestGeneratorTest/get_request.php b/tests/fixtures/RequestGeneratorTest/get_request.php index 0f3e2bd2..f3baadfc 100644 --- a/tests/fixtures/RequestGeneratorTest/get_request.php +++ b/tests/fixtures/RequestGeneratorTest/get_request.php @@ -14,7 +14,7 @@ public function rules(): array return [ 'with' => 'array', - 'with.*' => 'string|required|in:' . $availableRelations, + 'with.*' => 'required|string|in:' . $availableRelations, ]; } diff --git a/tests/fixtures/RequestGeneratorTest/search_request.php b/tests/fixtures/RequestGeneratorTest/search_request.php index 7e76ce95..ad7b837d 100644 --- a/tests/fixtures/RequestGeneratorTest/search_request.php +++ b/tests/fixtures/RequestGeneratorTest/search_request.php @@ -12,16 +12,16 @@ public function rules(): array $availableRelations = implode(',', $this->getAvailableRelations()); return [ - 'user_id' => 'integer|exists:users,id|required', + 'user_id' => 'required|integer|exists:users,id', 'page' => 'integer', 'per_page' => 'integer', 'is_published' => 'boolean', 'desc' => 'boolean', 'all' => 'boolean', - 'with' => 'array', 'order_by' => 'string|in:' . $this->getOrderableFields(Post::class), 'query' => 'string|nullable', - 'with.*' => 'string|in:' . $availableRelations, + 'with' => 'array', + 'with.*' => 'required|string|in:' . $availableRelations, ]; } diff --git a/tests/fixtures/RequestGeneratorTest/update_request.php b/tests/fixtures/RequestGeneratorTest/update_request.php index a1eae966..9e888c88 100644 --- a/tests/fixtures/RequestGeneratorTest/update_request.php +++ b/tests/fixtures/RequestGeneratorTest/update_request.php @@ -11,7 +11,7 @@ class UpdatePostRequest extends Request public function rules(): array { return [ - 'user_id' => 'integer|exists:users,id|required', + 'user_id' => 'required|integer|exists:users,id', 'is_draft' => 'boolean', 'is_published' => 'boolean', ];