From 7eaae3c86f106c204efacb5a1497a0cf9ba97cb0 Mon Sep 17 00:00:00 2001 From: pirs1337 Date: Tue, 4 Nov 2025 13:01:14 +0600 Subject: [PATCH 1/2] refactor: correct rules generation refs: https://github.com/RonasIT/laravel-entity-generator/issues/206 --- src/Generators/RequestsGenerator.php | 6 +++--- tests/fixtures/CommandTest/get_request.php | 2 +- tests/fixtures/CommandTest/search_request.php | 2 +- .../fixtures/CommandTest/search_request_subfolder_model.php | 2 +- tests/fixtures/RequestGeneratorTest/create_request.php | 2 +- tests/fixtures/RequestGeneratorTest/get_request.php | 2 +- tests/fixtures/RequestGeneratorTest/search_request.php | 4 ++-- tests/fixtures/RequestGeneratorTest/update_request.php | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Generators/RequestsGenerator.php b/src/Generators/RequestsGenerator.php index 295df05b..3c6062b5 100644 --- a/src/Generators/RequestsGenerator.php +++ b/src/Generators/RequestsGenerator.php @@ -133,12 +133,12 @@ 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); @@ -185,7 +185,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..d9965a23 100644 --- a/tests/fixtures/CommandTest/search_request.php +++ b/tests/fixtures/CommandTest/search_request.php @@ -17,8 +17,8 @@ public function rules(): array 'order_by' => 'string|in:' . $this->getOrderableFields(Post::class), 'desc' => 'boolean', 'all' => 'boolean', - 'with' => 'array', 'query' => 'string|nullable', + 'with' => 'array', 'with.*' => '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..f6c3f2ae 100644 --- a/tests/fixtures/CommandTest/search_request_subfolder_model.php +++ b/tests/fixtures/CommandTest/search_request_subfolder_model.php @@ -17,8 +17,8 @@ public function rules(): array 'order_by' => 'string|in:' . $this->getOrderableFields(Post::class), 'desc' => 'boolean', 'all' => 'boolean', - 'with' => 'array', 'query' => 'string|nullable', + 'with' => 'array', 'with.*' => '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..7d6b94dc 100644 --- a/tests/fixtures/RequestGeneratorTest/search_request.php +++ b/tests/fixtures/RequestGeneratorTest/search_request.php @@ -12,15 +12,15 @@ 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' => 'array', 'with.*' => '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', ]; From e3f91b9b638c85f6f3321080cda4b97567c02b52 Mon Sep 17 00:00:00 2001 From: pirs1337 Date: Tue, 4 Nov 2025 13:57:15 +0600 Subject: [PATCH 2/2] refactor: correct rules generation refs: https://github.com/RonasIT/laravel-entity-generator/issues/206 --- src/Generators/RequestsGenerator.php | 2 +- tests/fixtures/CommandTest/search_request.php | 2 +- tests/fixtures/CommandTest/search_request_subfolder_model.php | 2 +- tests/fixtures/RequestGeneratorTest/search_request.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Generators/RequestsGenerator.php b/src/Generators/RequestsGenerator.php index 3c6062b5..710a000a 100644 --- a/src/Generators/RequestsGenerator.php +++ b/src/Generators/RequestsGenerator.php @@ -141,7 +141,7 @@ protected function getSearchValidationParameters(): array $parameters['string-required'] = ['with.*']; - return $this->getValidationParameters($parameters, false); + return $this->getValidationParameters($parameters, true); } public function getValidationParameters($parameters, $requiredAvailable): array diff --git a/tests/fixtures/CommandTest/search_request.php b/tests/fixtures/CommandTest/search_request.php index d9965a23..fdfb22ba 100644 --- a/tests/fixtures/CommandTest/search_request.php +++ b/tests/fixtures/CommandTest/search_request.php @@ -19,7 +19,7 @@ public function rules(): array 'all' => 'boolean', 'query' => 'string|nullable', 'with' => 'array', - 'with.*' => 'string|in:' . $availableRelations, + '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 f6c3f2ae..3f864526 100644 --- a/tests/fixtures/CommandTest/search_request_subfolder_model.php +++ b/tests/fixtures/CommandTest/search_request_subfolder_model.php @@ -19,7 +19,7 @@ public function rules(): array 'all' => 'boolean', 'query' => 'string|nullable', 'with' => 'array', - 'with.*' => 'string|in:' . $availableRelations, + 'with.*' => 'required|string|in:' . $availableRelations, ]; } diff --git a/tests/fixtures/RequestGeneratorTest/search_request.php b/tests/fixtures/RequestGeneratorTest/search_request.php index 7d6b94dc..ad7b837d 100644 --- a/tests/fixtures/RequestGeneratorTest/search_request.php +++ b/tests/fixtures/RequestGeneratorTest/search_request.php @@ -21,7 +21,7 @@ public function rules(): array 'order_by' => 'string|in:' . $this->getOrderableFields(Post::class), 'query' => 'string|nullable', 'with' => 'array', - 'with.*' => 'string|in:' . $availableRelations, + 'with.*' => 'required|string|in:' . $availableRelations, ]; }